bool JSDOMWindowBase::supportsRichSourceInfo(const JSGlobalObject* object) { const JSDOMWindowBase* thisObject = static_cast<const JSDOMWindowBase*>(object); Frame* frame = thisObject->wrapped().frame(); if (!frame) return false; Page* page = frame->page(); if (!page) return false; bool enabled = page->inspectorController().enabled(); ASSERT(enabled || !thisObject->debugger()); ASSERT(enabled || !supportsProfiling(thisObject)); return enabled; }
bool RenderTheme::isActive(const RenderObject* o) const { Node* node = o->node(); if (!node) return false; Frame* frame = node->document()->frame(); if (!frame) return false; Page* page = frame->page(); if (!page) return false; return page->focusController()->isActive(); }
void FrameLoaderClient::didTransferChildFrameToNewDocument(WebCore::Page*) { ASSERT(m_frame); // Update the frame's webview to the new parent's webview. Frame* coreFrame = core(m_frame); WebKitWebView* webView = getViewFromFrame(m_frame); Frame* parentCoreFrame = coreFrame->tree()->parent(); WebKitWebFrame* parentKitFrame = kit(parentCoreFrame); WebKitWebView* parentWebView = getViewFromFrame(parentKitFrame); if (webView != parentWebView) m_frame->priv->webView = parentWebView; ASSERT(core(getViewFromFrame(m_frame)) == coreFrame->page()); }
bool JSDOMWindowBase::supportsProfiling() const { #if !ENABLE(JAVASCRIPT_DEBUGGER) || !ENABLE(INSPECTOR) return false; #else Frame* frame = impl()->frame(); if (!frame) return false; Page* page = frame->page(); if (!page) return false; return page->inspectorController()->profilerEnabled(); #endif }
void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger formSubmissionTrigger) { FrameView* view = document().view(); Frame* frame = document().frame(); if (!view || !frame || !frame->page()) return; if (m_isSubmittingOrPreparingForSubmission) { m_shouldSubmit = true; return; } m_isSubmittingOrPreparingForSubmission = true; m_wasUserSubmitted = processingUserGesture; RefPtr<HTMLFormControlElement> firstSuccessfulSubmitButton; bool needButtonActivation = activateSubmitButton; // do we need to activate a submit button? for (unsigned i = 0; i < m_associatedElements.size(); ++i) { FormAssociatedElement* associatedElement = m_associatedElements[i]; if (!associatedElement->isFormControlElement()) continue; if (needButtonActivation) { HTMLFormControlElement* control = toHTMLFormControlElement(associatedElement); if (control->isActivatedSubmit()) needButtonActivation = false; else if (firstSuccessfulSubmitButton == 0 && control->isSuccessfulSubmitButton()) firstSuccessfulSubmitButton = control; } } if (needButtonActivation && firstSuccessfulSubmitButton) firstSuccessfulSubmitButton->setActivatedSubmit(true); RefPtr<FormSubmission> formSubmission = FormSubmission::create(this, m_attributes, event, formSubmissionTrigger); EventQueueScope scopeForDialogClose; // Delay dispatching 'close' to dialog until done submitting. if (formSubmission->method() == FormSubmission::DialogMethod) submitDialog(formSubmission.release()); else scheduleFormSubmission(formSubmission.release()); if (needButtonActivation && firstSuccessfulSubmitButton) firstSuccessfulSubmitButton->setActivatedSubmit(false); m_shouldSubmit = false; m_isSubmittingOrPreparingForSubmission = false; }
bool JSDOMWindowBase::supportsProfiling(const JSGlobalObject* object) { #if !ENABLE(JAVASCRIPT_DEBUGGER) || !ENABLE(INSPECTOR) return false; #else const JSDOMWindowBase* thisObject = static_cast<const JSDOMWindowBase*>(object); Frame* frame = thisObject->impl()->frame(); if (!frame) return false; Page* page = frame->page(); if (!page) return false; return page->inspectorController()->profilerEnabled(); #endif }
bool JSDOMWindowBase::supportsProfiling(const JSGlobalObject* object) { #if !ENABLE(INSPECTOR) UNUSED_PARAM(object); return false; #else const JSDOMWindowBase* thisObject = static_cast<const JSDOMWindowBase*>(object); Frame* frame = thisObject->impl().frame(); if (!frame) return false; Page* page = frame->page(); if (!page) return false; return page->inspectorController().profilerEnabled(); #endif // ENABLE(INSPECTOR) }
void RootInlineBox::paintCustomHighlight(RenderObject::PaintInfo& paintInfo, int tx, int ty, const AtomicString& highlightType) { if (!renderer()->shouldPaintWithinRoot(paintInfo) || renderer()->style()->visibility() != VISIBLE || paintInfo.phase != PaintPhaseForeground) return; Frame* frame = renderer()->document()->frame(); if (!frame) return; Page* page = frame->page(); if (!page) return; // Get the inflated rect so that we can properly hit test. FloatRect rootRect(tx + x(), ty + selectionTop(), width(), selectionHeight()); FloatRect inflatedRect = page->chrome()->client()->customHighlightRect(renderer()->node(), highlightType, rootRect); if (inflatedRect.intersects(paintInfo.rect)) page->chrome()->client()->paintCustomHighlight(renderer()->node(), highlightType, rootRect, rootRect, false, true); }
void FrameLoaderClientEfl::didTransferChildFrameToNewDocument(Page*) { ASSERT(m_frame); Frame* currentFrame = EWKPrivate::coreFrame(m_frame); Evas_Object* currentView = ewk_frame_view_get(m_frame); Frame* parentFrame = currentFrame->tree()->parent(); FrameLoaderClientEfl* client = static_cast<FrameLoaderClientEfl*>(parentFrame->loader()->client()); Evas_Object* clientFrame = client ? client->webFrame() : 0; Evas_Object* clientView = ewk_frame_view_get(clientFrame); if (currentView != clientView) { ewk_frame_view_set(m_frame, clientView); m_view = clientView; } ASSERT(ewk_view_core_page_get(ewk_frame_view_get(m_frame)) == currentFrame->page()); }
void InspectorFrontendClientLocal::openInNewTab(const String& url) { UserGestureIndicator indicator(DefinitelyProcessingUserGesture); Page* page = m_inspectorController->inspectedPage(); Frame* mainFrame = page->mainFrame(); FrameLoadRequest request(mainFrame->document()->securityOrigin(), ResourceRequest(), "_blank"); bool created; WindowFeatures windowFeatures; Frame* frame = WebCore::createWindow(mainFrame, mainFrame, request, windowFeatures, created); if (!frame) return; frame->loader()->setOpener(mainFrame); frame->page()->setOpenedByDOM(); // FIXME: Why does one use mainFrame and the other frame? frame->loader()->changeLocation(mainFrame->document()->securityOrigin(), frame->document()->completeURL(url), "", false, false); }
void FrameLoaderClient::transitionToCommittedForNewPage() { WebKitWebView* containingWindow = getViewFromFrame(m_frame); IntSize size = IntSize(GTK_WIDGET(containingWindow)->allocation.width, GTK_WIDGET(containingWindow)->allocation.height); bool transparent = webkit_web_view_get_transparent(containingWindow); Color backgroundColor = transparent ? WebCore::Color::transparent : WebCore::Color::white; Frame* frame = core(m_frame); ASSERT(frame); frame->createView(size, backgroundColor, transparent, IntSize(), false); // We need to do further manipulation on the FrameView if it was the mainFrame if (frame != frame->page()->mainFrame()) return; WebKitWebViewPrivate* priv = WEBKIT_WEB_VIEW_GET_PRIVATE(containingWindow); frame->view()->setGtkAdjustments(priv->horizontalAdjustment, priv->verticalAdjustment); }
Frame* createWindow(const String& urlString, const AtomicString& frameName, const WindowFeatures& windowFeatures, DOMWindow* activeWindow, Frame* firstFrame, Frame* openerFrame, DOMWindow::PrepareDialogFunction function, void* functionContext) { Frame* activeFrame = activeWindow->frame(); KURL completedURL = urlString.isEmpty() ? KURL(ParsedURLString, emptyString()) : firstFrame->document()->completeURL(urlString); if (!completedURL.isEmpty() && !completedURL.isValid()) { // Don't expose client code to invalid URLs. activeWindow->printErrorMessage("Unable to open a window with invalid URL '" + completedURL.string() + "'.\n"); return 0; } // For whatever reason, Firefox uses the first frame to determine the outgoingReferrer. We replicate that behavior here. String referrer = SecurityPolicy::generateReferrerHeader(firstFrame->document()->referrerPolicy(), completedURL, firstFrame->loader()->outgoingReferrer()); ResourceRequest request(completedURL, referrer); FrameLoader::addHTTPOriginIfNeeded(request, firstFrame->loader()->outgoingOrigin()); FrameLoadRequest frameRequest(activeWindow->document()->securityOrigin(), request, frameName); // We pass the opener frame for the lookupFrame in case the active frame is different from // the opener frame, and the name references a frame relative to the opener frame. bool created; Frame* newFrame = createWindow(activeFrame, openerFrame, frameRequest, windowFeatures, created); if (!newFrame) return 0; newFrame->loader()->setOpener(openerFrame); newFrame->page()->setOpenedByDOM(); if (newFrame->domWindow()->isInsecureScriptAccess(activeWindow, completedURL)) return newFrame; if (function) function(newFrame->domWindow(), functionContext); if (created) { FrameLoadRequest request(activeWindow->document()->securityOrigin(), ResourceRequest(completedURL, referrer)); newFrame->loader()->load(request); } else if (!urlString.isEmpty()) { newFrame->navigationScheduler()->scheduleLocationChange(activeWindow->document()->securityOrigin(), completedURL.string(), referrer, false); } return newFrame; }
bool JSDOMWindowBase::supportsRichSourceInfo() const { #if !ENABLE(JAVASCRIPT_DEBUGGER) || !ENABLE(INSPECTOR) return false; #else Frame* frame = impl()->frame(); if (!frame) return false; Page* page = frame->page(); if (!page) return false; bool enabled = page->inspectorController()->enabled(); ASSERT(enabled || !debugger()); ASSERT(enabled || !supportsProfiling()); return enabled; #endif }
void WebFrameLoaderClient::transitionToCommittedForNewPage() { Frame* frame = core(m_webFrame); ASSERT(frame); Page* page = frame->page(); ASSERT(page); bool isMainFrame = frame == page->mainFrame(); /* if (isMainFrame && frame->view()) frame->view()->detachFromWindow();*/ frame->setView(0); m_webFrame->updateBackground(); WebView* webView = m_webFrame->webView(); FrameView* frameView; if (isMainFrame) { IntRect rect = webView->frameRect(); frameView = new FrameView(frame, rect.size()); } else frameView = new FrameView(frame); frame->setView(frameView); frameView->deref(); // FrameViews are created with a ref count of 1. Release this ref since we've assigned it to frame. BalWidget* viewWindow = webView->viewWindow(); if (viewWindow) frameView->setContainingWindow(viewWindow); /*if (isMainFrame) frameView->attachToWindow();*/ if (frame->ownerRenderer()) frame->ownerRenderer()->setWidget(frameView); if (HTMLFrameOwnerElement* owner = frame->ownerElement()) frame->view()->setScrollbarsMode(owner->scrollingMode()); }
bool JSDOMWindowBase::supportsRichSourceInfo(const JSGlobalObject* object) { #if !ENABLE(JAVASCRIPT_DEBUGGER) || !ENABLE(INSPECTOR) return false; #else const JSDOMWindowBase* thisObject = static_cast<const JSDOMWindowBase*>(object); Frame* frame = thisObject->impl()->frame(); if (!frame) return false; Page* page = frame->page(); if (!page) return false; bool enabled = page->inspectorController()->enabled(); ASSERT(enabled || !thisObject->debugger()); ASSERT(enabled || !supportsProfiling(thisObject)); return enabled; #endif }
void V8ConsoleMessage::handler(v8::Handle<v8::Message> message, v8::Handle<v8::Value> data) { // Use the frame where JavaScript is called from. Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); if (!frame) return; Page* page = frame->page(); if (!page) return; v8::Handle<v8::String> errorMessageString = message->Get(); ASSERT(!errorMessageString.IsEmpty()); String errorMessage = toWebCoreString(errorMessageString); v8::Handle<v8::Value> resourceName = message->GetScriptResourceName(); bool useURL = resourceName.IsEmpty() || !resourceName->IsString(); String resourceNameString = useURL ? frame->document()->url() : toWebCoreString(resourceName); V8ConsoleMessage consoleMessage(errorMessage, resourceNameString, message->GetLineNumber()); consoleMessage.dispatchNow(page); }
bool RenderIFrame::flattenFrame() const { Frame* frame = iframeElement().document().frame(); bool enabled = frame && frame->settings().frameFlatteningEnabled(); if (!enabled || !frame->page()) return false; if (style().width().isFixed() && style().height().isFixed()) { // Do not flatten iframes with scrolling="no". if (iframeElement().scrollingMode() == ScrollbarAlwaysOff) return false; if (style().width().value() <= 0 || style().height().value() <= 0) return false; } // Do not flatten offscreen inner frames during frame flattening, as flattening might make them visible. IntRect boundingRect = absoluteBoundingBoxRectIgnoringTransforms(); return boundingRect.maxX() > 0 && boundingRect.maxY() > 0; }
void InspectorPageAgent::open(ErrorString*, const String& url, const bool* const inNewWindow) { Frame* mainFrame = m_page->mainFrame(); Frame* frame; if (inNewWindow && *inNewWindow) { FrameLoadRequest request(mainFrame->document()->securityOrigin(), ResourceRequest(), "_blank"); bool created; WindowFeatures windowFeatures; frame = WebCore::createWindow(mainFrame, mainFrame, request, windowFeatures, created); if (!frame) return; frame->loader()->setOpener(mainFrame); frame->page()->setOpenedByDOM(); } else frame = mainFrame; UserGestureIndicator indicator(DefinitelyProcessingUserGesture); frame->loader()->changeLocation(mainFrame->document()->securityOrigin(), frame->loader()->completeURL(url), "", false, false); }
void ContextMenu::addInspectElementItem() { Node* node = m_hitTestResult.innerNonSharedNode(); if (!node) return; Frame* frame = node->document()->frame(); if (!frame) return; Page* page = frame->page(); if (!page) return; if (!page->inspectorController()) return; ContextMenuItem InspectElementItem(ActionType, ContextMenuItemTagInspectElement, contextMenuItemTagInspectElement()); appendItem(*separatorItem()); appendItem(InspectElementItem); }
PassRefPtr<Frame> WebFrameLoaderClient::createFrame(const KURL& URL, const String& name, HTMLFrameOwnerElement* ownerElement, const String& referrer) { Frame* coreFrame = core(m_webFrame); ASSERT(coreFrame); COMPtr<WebFrame> webFrame(AdoptCOM, WebFrame::createInstance()); RefPtr<Frame> childFrame = webFrame->init(m_webFrame->webView(), coreFrame->page(), ownerElement); coreFrame->tree()->appendChild(childFrame); childFrame->tree()->setName(name); childFrame->init(); loadURLIntoChild(URL, referrer, webFrame.get()); // The frame's onload handler may have removed it from the document. if (!childFrame->tree()->parent()) return 0; return childFrame.release(); }
void WebFrameLoaderClient::transitionToCommittedForNewPage() { Frame* frame = core(m_webFrame); ASSERT(frame); Page* page = frame->page(); ASSERT(page); bool isMainFrame = frame == page->mainFrame(); if (isMainFrame && frame->view()) frame->view()->setParentVisible(false); frame->setView(0); WebView* webView = m_webFrame->webView(); FrameView* frameView; if (isMainFrame) { RECT rect; webView->frameRect(&rect); frameView = new FrameView(frame, IntRect(rect).size()); } else frameView = new FrameView(frame); frame->setView(frameView); frameView->deref(); // FrameViews are created with a ref count of 1. Release this ref since we've assigned it to frame. m_webFrame->updateBackground(); if (isMainFrame) frameView->setParentVisible(true); if (frame->ownerRenderer()) frame->ownerRenderer()->setWidget(frameView); if (HTMLFrameOwnerElement* owner = frame->ownerElement()) frame->view()->setCanHaveScrollbars(owner->scrollingMode() != ScrollbarAlwaysOff); }
void V8Proxy::reportUnsafeAccessTo(Frame* target, DelayReporting delay) { ASSERT(target); Document* targetDocument = target->document(); if (!targetDocument) return; Frame* source = V8Proxy::retrieveFrameForEnteredContext(); if (!source || !source->document()) return; // Ignore error if the source document is gone. Document* sourceDocument = source->document(); // FIXME: This error message should contain more specifics of why the same // origin check has failed. String str = String::format("Unsafe JavaScript attempt to access frame " "with URL %s from frame with URL %s. " "Domains, protocols and ports must match.\n", targetDocument->url().string().utf8().data(), sourceDocument->url().string().utf8().data()); // Build a console message with fake source ID and line number. const String kSourceID = ""; const int kLineNumber = 1; V8ConsoleMessage message(str, kSourceID, kLineNumber); if (delay == ReportNow) { // NOTE: Safari prints the message in the target page, but it seems like // it should be in the source page. Even for delayed messages, we put it in // the source page; see V8ConsoleMessage::processDelayed(). message.dispatchNow(source->page()); } else { ASSERT(delay == ReportLater); // We cannot safely report the message eagerly, because this may cause // allocations and GCs internally in V8 and we cannot handle that at this // point. Therefore we delay the reporting. message.dispatchLater(); } }
void FrameLoaderClient::transitionToCommittedForNewPage() { WebKitWebView* containingWindow = getViewFromFrame(m_frame); GtkAllocation allocation; #if GTK_CHECK_VERSION(2, 18, 0) gtk_widget_get_allocation(GTK_WIDGET(containingWindow), &allocation); #else allocation = GTK_WIDGET(containingWindow)->allocation; #endif IntSize size = IntSize(allocation.width, allocation.height); bool transparent = webkit_web_view_get_transparent(containingWindow); Color backgroundColor = transparent ? WebCore::Color::transparent : WebCore::Color::white; Frame* frame = core(m_frame); ASSERT(frame); frame->createView(size, backgroundColor, transparent, IntSize(), false); // We need to do further manipulation on the FrameView if it was the mainFrame if (frame != frame->page()->mainFrame()) return; postCommitFrameViewSetup(m_frame); }
PassRefPtr<Frame> WebFrameLoaderClient::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement, const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight) { WebPage* webPage = m_frame->page(); RefPtr<WebFrame> subframe = WebFrame::createSubframe(webPage, name, ownerElement); Frame* coreSubframe = subframe->coreFrame(); if (!coreSubframe) return 0; // The creation of the frame may have run arbitrary JavaScript that removed it from the page already. if (!coreSubframe->page()) return 0; m_frame->coreFrame()->loader()->loadURLIntoChildFrame(url, referrer, coreSubframe); // The frame's onload handler may have removed it from the document. if (!coreSubframe->tree()->parent()) return 0; return coreSubframe; }
WTF::PassRefPtr<WebCore::Frame> FrameLoaderClientAndroid::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement, const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight) { Frame* parent = ownerElement->document()->frame(); FrameLoaderClientAndroid* loaderC = new FrameLoaderClientAndroid(m_webFrame); RefPtr<Frame> pFrame = Frame::create(parent->page(), ownerElement, loaderC); Frame* newFrame = pFrame.get(); loaderC->setFrame(newFrame); // Append the subframe to the parent and set the name of the subframe. The name must be set after // appending the child so that the name becomes unique. parent->tree()->appendChild(newFrame); newFrame->tree()->setName(name); // Create a new FrameView and WebFrameView for the child frame to draw into. RefPtr<FrameView> frameView = FrameView::create(newFrame); WebFrameView* webFrameView = new WebFrameView(frameView.get(), WebViewCore::getWebViewCore(parent->view())); // frameView Retains webFrameView, so call Release for webFrameView Release(webFrameView); // Attach the frameView to the newFrame. newFrame->setView(frameView); newFrame->init(); newFrame->selection()->setFocused(true); LOGV("::WebCore:: createSubFrame returning %p", newFrame); // The creation of the frame may have run arbitrary JavaScript that removed it from the page already. if (!pFrame->page()) return 0; parent->loader()->loadURLIntoChildFrame(url, referrer, pFrame.get()); // onLoad may cuase the frame to be removed from the document. Allow the RefPtr to delete the child frame. if (!pFrame->tree()->parent()) return NULL; return pFrame.release(); }
static PassRefPtr<InspectorObject> buildObjectForCSSRegionContentClip(RenderRegion* region) { Frame* containingFrame = region->document().frame(); if (!containingFrame) return nullptr; FrameView* containingView = containingFrame->view(); FrameView* mainView = containingFrame->page()->mainFrame().view(); RenderFlowThread* flowThread = region->flowThread(); // Get the clip box of the current region and covert it into an absolute quad. LayoutRect flippedRegionRect(region->flowThreadPortionOverflowRect()); flowThread->flipForWritingMode(flippedRegionRect); // Apply any border or padding of the region. flippedRegionRect.setLocation(region->contentBoxRect().location()); FloatQuad clipQuad = region->localToAbsoluteQuad(FloatRect(flippedRegionRect)); contentsQuadToPage(mainView, containingView, clipQuad); RefPtr<InspectorObject> regionObject = InspectorObject::create(); regionObject->setArray("quad", buildArrayForQuad(clipQuad)); return regionObject.release(); }
void InspectorCanvasAgent::findFramesWithUninstrumentedCanvases() { class NodeVisitor : public WrappedNodeVisitor { public: NodeVisitor(Page* page, FramesWithUninstrumentedCanvases& result) : m_page(page) , m_framesWithUninstrumentedCanvases(result) { } virtual void visitNode(Node* node) OVERRIDE { if (!node->hasTagName(HTMLNames::canvasTag) || !node->document().frame()) return; Frame* frame = node->document().frame(); if (frame->page() != m_page) return; if (toHTMLCanvasElement(node)->renderingContext()) m_framesWithUninstrumentedCanvases.set(frame, true); } private:
void HTMLFormElement::scheduleFormSubmission(PassRefPtr<FormSubmission> submission) { ASSERT(submission->method() == FormSubmission::PostMethod || submission->method() == FormSubmission::GetMethod); ASSERT(submission->data()); ASSERT(submission->state()); if (submission->action().isEmpty()) return; if (document().isSandboxed(SandboxForms)) { // FIXME: This message should be moved off the console once a solution to https://bugs.webkit.org/show_bug.cgi?id=103274 exists. document().addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, "Blocked form submission to '" + submission->action().elidedString() + "' because the form's frame is sandboxed and the 'allow-forms' permission is not set."); return; } if (protocolIsJavaScript(submission->action())) { if (!document().contentSecurityPolicy()->allowFormAction(KURL(submission->action()))) return; document().frame()->script().executeScriptIfJavaScriptURL(submission->action()); return; } Frame* targetFrame = document().frame()->loader().findFrameForNavigation(submission->target(), submission->state()->sourceDocument()); if (!targetFrame) { if (!DOMWindow::allowPopUp(document().frame()) && !UserGestureIndicator::processingUserGesture()) return; targetFrame = document().frame(); } else { submission->clearTarget(); } if (!targetFrame->page()) return; submission->setReferrer(document().frame()->loader().outgoingReferrer()); submission->setOrigin(document().frame()->loader().outgoingOrigin()); targetFrame->navigationScheduler().scheduleFormSubmission(submission); }
static void buildRendererHighlight(RenderObject* renderer, RenderRegion* region, const HighlightConfig& highlightConfig, Highlight* highlight, InspectorOverlay::CoordinateSystem coordinateSystem) { Frame* containingFrame = renderer->document().frame(); if (!containingFrame) return; highlight->setDataFromConfig(highlightConfig); FrameView* containingView = containingFrame->view(); FrameView* mainView = containingFrame->page()->mainFrame().view(); // RenderSVGRoot should be highlighted through the isBox() code path, all other SVG elements should just dump their absoluteQuads(). bool isSVGRenderer = renderer->node() && renderer->node()->isSVGElement() && !renderer->isSVGRoot(); if (isSVGRenderer) { highlight->type = HighlightTypeRects; renderer->absoluteQuads(highlight->quads); for (size_t i = 0; i < highlight->quads.size(); ++i) contentsQuadToCoordinateSystem(mainView, containingView, highlight->quads[i], coordinateSystem); } else if (renderer->isBox() || renderer->isRenderInline()) { LayoutRect contentBox; LayoutRect paddingBox; LayoutRect borderBox; LayoutRect marginBox; if (renderer->isBox()) { RenderBox* renderBox = toRenderBox(renderer); LayoutBoxExtent margins(renderBox->marginTop(), renderBox->marginRight(), renderBox->marginBottom(), renderBox->marginLeft()); if (!renderBox->isOutOfFlowPositioned() && region) { RenderBox::LogicalExtentComputedValues computedValues; renderBox->computeLogicalWidthInRegion(computedValues, region); margins.mutableLogicalLeft(renderBox->style().writingMode()) = computedValues.m_margins.m_start; margins.mutableLogicalRight(renderBox->style().writingMode()) = computedValues.m_margins.m_end; } paddingBox = renderBox->clientBoxRectInRegion(region); contentBox = LayoutRect(paddingBox.x() + renderBox->paddingLeft(), paddingBox.y() + renderBox->paddingTop(), paddingBox.width() - renderBox->paddingLeft() - renderBox->paddingRight(), paddingBox.height() - renderBox->paddingTop() - renderBox->paddingBottom()); borderBox = LayoutRect(paddingBox.x() - renderBox->borderLeft(), paddingBox.y() - renderBox->borderTop(), paddingBox.width() + renderBox->borderLeft() + renderBox->borderRight(), paddingBox.height() + renderBox->borderTop() + renderBox->borderBottom()); marginBox = LayoutRect(borderBox.x() - margins.left(), borderBox.y() - margins.top(), borderBox.width() + margins.left() + margins.right(), borderBox.height() + margins.top() + margins.bottom()); } else { RenderInline* renderInline = toRenderInline(renderer); // RenderInline's bounding box includes paddings and borders, excludes margins. borderBox = renderInline->linesBoundingBox(); paddingBox = LayoutRect(borderBox.x() + renderInline->borderLeft(), borderBox.y() + renderInline->borderTop(), borderBox.width() - renderInline->borderLeft() - renderInline->borderRight(), borderBox.height() - renderInline->borderTop() - renderInline->borderBottom()); contentBox = LayoutRect(paddingBox.x() + renderInline->paddingLeft(), paddingBox.y() + renderInline->paddingTop(), paddingBox.width() - renderInline->paddingLeft() - renderInline->paddingRight(), paddingBox.height() - renderInline->paddingTop() - renderInline->paddingBottom()); // Ignore marginTop and marginBottom for inlines. marginBox = LayoutRect(borderBox.x() - renderInline->marginLeft(), borderBox.y(), borderBox.width() + renderInline->horizontalMarginExtent(), borderBox.height()); } FloatQuad absContentQuad; FloatQuad absPaddingQuad; FloatQuad absBorderQuad; FloatQuad absMarginQuad; if (region) { RenderFlowThread* flowThread = region->flowThread(); // Figure out the quads in the space of the RenderFlowThread. absContentQuad = renderer->localToContainerQuad(FloatRect(contentBox), flowThread); absPaddingQuad = renderer->localToContainerQuad(FloatRect(paddingBox), flowThread); absBorderQuad = renderer->localToContainerQuad(FloatRect(borderBox), flowThread); absMarginQuad = renderer->localToContainerQuad(FloatRect(marginBox), flowThread); // Move the quad relative to the space of the current region. LayoutRect flippedRegionRect(region->flowThreadPortionRect()); flowThread->flipForWritingMode(flippedRegionRect); FloatSize delta = region->contentBoxRect().location() - flippedRegionRect.location(); absContentQuad.move(delta); absPaddingQuad.move(delta); absBorderQuad.move(delta); absMarginQuad.move(delta); // Resolve the absolute quads starting from the current region. absContentQuad = region->localToAbsoluteQuad(absContentQuad); absPaddingQuad = region->localToAbsoluteQuad(absPaddingQuad); absBorderQuad = region->localToAbsoluteQuad(absBorderQuad); absMarginQuad = region->localToAbsoluteQuad(absMarginQuad); } else { absContentQuad = renderer->localToAbsoluteQuad(FloatRect(contentBox)); absPaddingQuad = renderer->localToAbsoluteQuad(FloatRect(paddingBox)); absBorderQuad = renderer->localToAbsoluteQuad(FloatRect(borderBox)); absMarginQuad = renderer->localToAbsoluteQuad(FloatRect(marginBox)); } contentsQuadToCoordinateSystem(mainView, containingView, absContentQuad, coordinateSystem); contentsQuadToCoordinateSystem(mainView, containingView, absPaddingQuad, coordinateSystem); contentsQuadToCoordinateSystem(mainView, containingView, absBorderQuad, coordinateSystem); contentsQuadToCoordinateSystem(mainView, containingView, absMarginQuad, coordinateSystem); highlight->type = HighlightTypeNode; highlight->quads.append(absMarginQuad); highlight->quads.append(absBorderQuad); highlight->quads.append(absPaddingQuad); highlight->quads.append(absContentQuad); } }
void ContextMenu::populate() { ContextMenuItem OpenLinkItem(ActionType, ContextMenuItemTagOpenLink, contextMenuItemTagOpenLink()); ContextMenuItem OpenLinkInNewWindowItem(ActionType, ContextMenuItemTagOpenLinkInNewWindow, contextMenuItemTagOpenLinkInNewWindow()); ContextMenuItem DownloadFileItem(ActionType, ContextMenuItemTagDownloadLinkToDisk, contextMenuItemTagDownloadLinkToDisk()); ContextMenuItem CopyLinkItem(ActionType, ContextMenuItemTagCopyLinkToClipboard, contextMenuItemTagCopyLinkToClipboard()); ContextMenuItem OpenImageInNewWindowItem(ActionType, ContextMenuItemTagOpenImageInNewWindow, contextMenuItemTagOpenImageInNewWindow()); ContextMenuItem DownloadImageItem(ActionType, ContextMenuItemTagDownloadImageToDisk, contextMenuItemTagDownloadImageToDisk()); ContextMenuItem CopyImageItem(ActionType, ContextMenuItemTagCopyImageToClipboard, contextMenuItemTagCopyImageToClipboard()); #if PLATFORM(MAC) ContextMenuItem SearchSpotlightItem(ActionType, ContextMenuItemTagSearchInSpotlight, contextMenuItemTagSearchInSpotlight()); ContextMenuItem LookInDictionaryItem(ActionType, ContextMenuItemTagLookUpInDictionary, contextMenuItemTagLookUpInDictionary()); #endif ContextMenuItem SearchWebItem(ActionType, ContextMenuItemTagSearchWeb, contextMenuItemTagSearchWeb()); ContextMenuItem CopyItem(ActionType, ContextMenuItemTagCopy, contextMenuItemTagCopy()); ContextMenuItem BackItem(ActionType, ContextMenuItemTagGoBack, contextMenuItemTagGoBack()); ContextMenuItem ForwardItem(ActionType, ContextMenuItemTagGoForward, contextMenuItemTagGoForward()); ContextMenuItem StopItem(ActionType, ContextMenuItemTagStop, contextMenuItemTagStop()); ContextMenuItem ReloadItem(ActionType, ContextMenuItemTagReload, contextMenuItemTagReload()); ContextMenuItem OpenFrameItem(ActionType, ContextMenuItemTagOpenFrameInNewWindow, contextMenuItemTagOpenFrameInNewWindow()); ContextMenuItem NoGuessesItem(ActionType, ContextMenuItemTagNoGuessesFound, contextMenuItemTagNoGuessesFound()); ContextMenuItem IgnoreSpellingItem(ActionType, ContextMenuItemTagIgnoreSpelling, contextMenuItemTagIgnoreSpelling()); ContextMenuItem LearnSpellingItem(ActionType, ContextMenuItemTagLearnSpelling, contextMenuItemTagLearnSpelling()); ContextMenuItem IgnoreGrammarItem(ActionType, ContextMenuItemTagIgnoreGrammar, contextMenuItemTagIgnoreGrammar()); ContextMenuItem CutItem(ActionType, ContextMenuItemTagCut, contextMenuItemTagCut()); ContextMenuItem PasteItem(ActionType, ContextMenuItemTagPaste, contextMenuItemTagPaste()); #if PLATFORM(GTK) ContextMenuItem DeleteItem(ActionType, ContextMenuItemTagDelete, contextMenuItemTagDelete()); ContextMenuItem SelectAllItem(ActionType, ContextMenuItemTagSelectAll, contextMenuItemTagSelectAll()); #endif HitTestResult result = hitTestResult(); Node* node = m_hitTestResult.innerNonSharedNode(); if (!node) return; #if PLATFORM(GTK) if (!result.isContentEditable() && node->isControl()) return; #endif Frame* frame = node->document()->frame(); if (!frame) return; if (!result.isContentEditable()) { FrameLoader* loader = frame->loader(); KURL linkURL = result.absoluteLinkURL(); if (!linkURL.isEmpty()) { if (loader->canHandleRequest(ResourceRequest(linkURL))) { appendItem(OpenLinkItem); appendItem(OpenLinkInNewWindowItem); appendItem(DownloadFileItem); } appendItem(CopyLinkItem); } KURL imageURL = result.absoluteImageURL(); if (!imageURL.isEmpty()) { if (!linkURL.isEmpty()) appendItem(*separatorItem()); appendItem(OpenImageInNewWindowItem); appendItem(DownloadImageItem); if (imageURL.isLocalFile() || m_hitTestResult.image()) appendItem(CopyImageItem); } if (imageURL.isEmpty() && linkURL.isEmpty()) { if (result.isSelected()) { if (selectionContainsPossibleWord(frame)) { #if PLATFORM(MAC) appendItem(SearchSpotlightItem); #endif appendItem(SearchWebItem); appendItem(*separatorItem()); #if PLATFORM(MAC) appendItem(LookInDictionaryItem); appendItem(*separatorItem()); #endif } appendItem(CopyItem); } else { #if PLATFORM(GTK) appendItem(BackItem); appendItem(ForwardItem); appendItem(StopItem); appendItem(ReloadItem); #else if (loader->canGoBackOrForward(-1)) appendItem(BackItem); if (loader->canGoBackOrForward(1)) appendItem(ForwardItem); // use isLoadingInAPISense rather than isLoading because Stop/Reload are // intended to match WebKit's API, not WebCore's internal notion of loading status if (loader->documentLoader()->isLoadingInAPISense()) appendItem(StopItem); else appendItem(ReloadItem); #endif if (frame->page() && frame != frame->page()->mainFrame()) appendItem(OpenFrameItem); } } } else { // Make an editing context menu SelectionController* selection = frame->selection(); bool inPasswordField = selection->isInPasswordField(); if (!inPasswordField) { // Consider adding spelling-related or grammar-related context menu items (never both, since a single selected range // is never considered a misspelling and bad grammar at the same time) bool misspelling = frame->editor()->isSelectionMisspelled(); bool badGrammar = !misspelling && (frame->editor()->isGrammarCheckingEnabled() && frame->editor()->isSelectionUngrammatical()); if (misspelling || badGrammar) { Vector<String> guesses = misspelling ? frame->editor()->guessesForMisspelledSelection() : frame->editor()->guessesForUngrammaticalSelection(); size_t size = guesses.size(); if (size == 0) { // If there's bad grammar but no suggestions (e.g., repeated word), just leave off the suggestions // list and trailing separator rather than adding a "No Guesses Found" item (matches AppKit) if (misspelling) { appendItem(NoGuessesItem); appendItem(*separatorItem()); } } else { for (unsigned i = 0; i < size; i++) { const String &guess = guesses[i]; if (!guess.isEmpty()) { ContextMenuItem item(ActionType, ContextMenuItemTagSpellingGuess, guess); appendItem(item); } } appendItem(*separatorItem()); } if (misspelling) { appendItem(IgnoreSpellingItem); appendItem(LearnSpellingItem); } else appendItem(IgnoreGrammarItem); appendItem(*separatorItem()); } } FrameLoader* loader = frame->loader(); KURL linkURL = result.absoluteLinkURL(); if (!linkURL.isEmpty()) { if (loader->canHandleRequest(ResourceRequest(linkURL))) { appendItem(OpenLinkItem); appendItem(OpenLinkInNewWindowItem); appendItem(DownloadFileItem); } appendItem(CopyLinkItem); appendItem(*separatorItem()); } if (result.isSelected() && !inPasswordField && selectionContainsPossibleWord(frame)) { #if PLATFORM(MAC) appendItem(SearchSpotlightItem); #endif appendItem(SearchWebItem); appendItem(*separatorItem()); #if PLATFORM(MAC) appendItem(LookInDictionaryItem); appendItem(*separatorItem()); #endif } appendItem(CutItem); appendItem(CopyItem); appendItem(PasteItem); #if PLATFORM(GTK) appendItem(DeleteItem); appendItem(*separatorItem()); appendItem(SelectAllItem); #endif if (!inPasswordField) { appendItem(*separatorItem()); #ifndef BUILDING_ON_TIGER ContextMenuItem SpellingAndGrammarMenuItem(SubmenuType, ContextMenuItemTagSpellingMenu, contextMenuItemTagSpellingMenu()); createAndAppendSpellingAndGrammarSubMenu(m_hitTestResult, SpellingAndGrammarMenuItem); appendItem(SpellingAndGrammarMenuItem); #else ContextMenuItem SpellingMenuItem(SubmenuType, ContextMenuItemTagSpellingMenu, contextMenuItemTagSpellingMenu()); createAndAppendSpellingSubMenu(m_hitTestResult, SpellingMenuItem); appendItem(SpellingMenuItem); #endif ContextMenuItem FontMenuItem(SubmenuType, ContextMenuItemTagFontMenu, contextMenuItemTagFontMenu()); createAndAppendFontSubMenu(m_hitTestResult, FontMenuItem); appendItem(FontMenuItem); #if PLATFORM(MAC) ContextMenuItem SpeechMenuItem(SubmenuType, ContextMenuItemTagSpeechMenu, contextMenuItemTagSpeechMenu()); createAndAppendSpeechSubMenu(m_hitTestResult, SpeechMenuItem); appendItem(SpeechMenuItem); #endif #if !PLATFORM(GTK) ContextMenuItem WritingDirectionMenuItem(SubmenuType, ContextMenuItemTagWritingDirectionMenu, contextMenuItemTagWritingDirectionMenu()); createAndAppendWritingDirectionSubMenu(m_hitTestResult, WritingDirectionMenuItem); appendItem(WritingDirectionMenuItem); if (Page* page = frame->page()) { if (Settings* settings = page->settings()) { bool includeTextDirectionSubmenu = settings->textDirectionSubmenuInclusionBehavior() == TextDirectionSubmenuAlwaysIncluded || settings->textDirectionSubmenuInclusionBehavior() == TextDirectionSubmenuAutomaticallyIncluded && frame->editor()->hasBidiSelection(); if (includeTextDirectionSubmenu) { ContextMenuItem TextDirectionMenuItem(SubmenuType, ContextMenuItemTagTextDirectionMenu, contextMenuItemTagTextDirectionMenu()); createAndAppendTextDirectionSubMenu(m_hitTestResult, TextDirectionMenuItem); appendItem(TextDirectionMenuItem); } } } #endif } } }