bool KeyframeAnimation::sendAnimationEvent(const AtomicString& eventType, double elapsedTime) { Document::ListenerType listenerType; if (eventType == eventNames().webkitAnimationIterationEvent) listenerType = Document::ANIMATIONITERATION_LISTENER; else if (eventType == eventNames().webkitAnimationEndEvent) listenerType = Document::ANIMATIONEND_LISTENER; else { ASSERT(eventType == eventNames().webkitAnimationStartEvent); if (m_startEventDispatched) return false; m_startEventDispatched = true; listenerType = Document::ANIMATIONSTART_LISTENER; } if (shouldSendEventForListener(listenerType)) { // Dispatch the event RefPtr<Element> element; if (m_object->node() && m_object->node()->isElementNode()) element = static_cast<Element*>(m_object->node()); ASSERT(!element || (element->document() && !element->document()->inPageCache())); if (!element) return false; // Schedule event handling m_compAnim->animationController()->addEventToDispatch(element, eventType, m_keyframes.animationName(), elapsedTime); // Restore the original (unanimated) style if (eventType == eventNames().webkitAnimationEndEvent && element->renderer()) setNeedsStyleRecalc(element.get()); return true; // Did dispatch an event } return false; // Did not dispatch an event }
DragOperation DragController::tryDHTMLDrag(DragData* dragData) { ASSERT(dragData); ASSERT(m_document); DragOperation op = DragOperationNone; RefPtr<Frame> frame = m_page->mainFrame(); RefPtr<FrameView> viewProtector = frame->view(); if (!viewProtector) return DragOperationNone; ClipboardAccessPolicy policy = frame->loader()->baseURL().isLocalFile() ? ClipboardReadable : ClipboardTypesReadable; RefPtr<Clipboard> clipboard = dragData->createClipboard(policy); DragOperation srcOp = dragData->draggingSourceOperationMask(); clipboard->setSourceOperation(srcOp); #ifdef __OWB__ if (frame->eventHandler()->updateDragAndDrop(createMouseEvent(dragData), clipboard.get())) { #else PlatformMouseEvent event = createMouseEvent(dragData); if (frame->eventHandler()->updateDragAndDrop(event, clipboard.get())) { #endif // *op unchanged if no source op was set if (!clipboard->destinationOperation(op)) { // The element accepted but they didn't pick an operation, so we pick one for them // (as does WinIE). if (srcOp & DragOperationCopy) op = DragOperationCopy; else if (srcOp & DragOperationMove || srcOp & DragOperationGeneric) op = DragOperationMove; else if (srcOp & DragOperationLink) op = DragOperationLink; else op = DragOperationGeneric; } else if (!(op & srcOp)) { op = DragOperationNone; } clipboard->setAccessPolicy(ClipboardNumb); // invalidate clipboard here for security return op; } return op; } bool DragController::mayStartDragAtEventLocation(const Frame* frame, const IntPoint& framePos) { ASSERT(frame); if (!frame->view() || !frame->renderer()) return false; HitTestResult mouseDownTarget = HitTestResult(framePos); mouseDownTarget = frame->eventHandler()->hitTestResultAtPoint(framePos, true); if (mouseDownTarget.image() && !mouseDownTarget.absoluteImageURL().isEmpty() && frame->settings()->loadsImagesAutomatically() && m_dragSourceAction & DragSourceActionImage) return true; if (!mouseDownTarget.absoluteLinkURL().isEmpty() && m_dragSourceAction & DragSourceActionLink && mouseDownTarget.isLiveLink()) return true; if (mouseDownTarget.isSelected() && m_dragSourceAction & DragSourceActionSelection) return true; return false; }
bool DragController::concludeEditDrag(DragData* dragData) { ASSERT(dragData); RefPtr<HTMLInputElement> fileInput = m_fileInputElementUnderMouse; if (m_fileInputElementUnderMouse) { m_fileInputElementUnderMouse->setCanReceiveDroppedFiles(false); m_fileInputElementUnderMouse = 0; } if (!m_documentUnderMouse) return false; IntPoint point = m_documentUnderMouse->view()->windowToContents(dragData->clientPosition()); Element* element = elementUnderMouse(m_documentUnderMouse.get(), point); if (!element) return false; Frame* innerFrame = element->ownerDocument()->frame(); ASSERT(innerFrame); if (m_page->dragCaretController()->hasCaret() && !dispatchTextInputEventFor(innerFrame, dragData)) return true; if (dragData->containsColor()) { Color color = dragData->asColor(); if (!color.isValid()) return false; RefPtr<Range> innerRange = innerFrame->selection()->toNormalizedRange(); RefPtr<StylePropertySet> style = StylePropertySet::create(); style->setProperty(CSSPropertyColor, color.serialized(), false); if (!innerFrame->editor()->shouldApplyStyle(style.get(), innerRange.get())) return false; m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData); innerFrame->editor()->applyStyle(style.get(), EditActionSetColor); return true; } if (dragData->containsFiles() && fileInput) { // fileInput should be the element we hit tested for, unless it was made // display:none in a drop event handler. ASSERT(fileInput == element || !fileInput->renderer()); if (fileInput->disabled()) return false; Vector<String> filenames; dragData->asFilenames(filenames); if (filenames.isEmpty()) return false; fileInput->receiveDroppedFiles(filenames); m_client->willPerformDragDestinationAction(DragDestinationActionUpload, dragData); return true; } if (!m_page->dragController()->canProcessDrag(dragData)) { m_page->dragCaretController()->clear(); return false; } VisibleSelection dragCaret = m_page->dragCaretController()->caretPosition(); m_page->dragCaretController()->clear(); RefPtr<Range> range = dragCaret.toNormalizedRange(); RefPtr<Element> rootEditableElement = innerFrame->selection()->rootEditableElement(); // For range to be null a WebKit client must have done something bad while // manually controlling drag behaviour if (!range) return false; CachedResourceLoader* cachedResourceLoader = range->ownerDocument()->cachedResourceLoader(); ResourceCacheValidationSuppressor validationSuppressor(cachedResourceLoader); if (dragIsMove(innerFrame->selection(), dragData) || dragCaret.isContentRichlyEditable()) { bool chosePlainText = false; RefPtr<DocumentFragment> fragment = documentFragmentFromDragData(dragData, innerFrame, range, true, chosePlainText); if (!fragment || !innerFrame->editor()->shouldInsertFragment(fragment, range, EditorInsertActionDropped)) { return false; } m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData); if (dragIsMove(innerFrame->selection(), dragData)) { // NSTextView behavior is to always smart delete on moving a selection, // but only to smart insert if the selection granularity is word granularity. bool smartDelete = innerFrame->editor()->smartInsertDeleteEnabled(); bool smartInsert = smartDelete && innerFrame->selection()->granularity() == WordGranularity && dragData->canSmartReplace(); applyCommand(MoveSelectionCommand::create(fragment, dragCaret.base(), smartInsert, smartDelete)); } else { if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) { ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::PreventNesting; if (dragData->canSmartReplace()) options |= ReplaceSelectionCommand::SmartReplace; if (chosePlainText) options |= ReplaceSelectionCommand::MatchStyle; applyCommand(ReplaceSelectionCommand::create(m_documentUnderMouse.get(), fragment, options)); } } } else { String text = dragData->asPlainText(innerFrame); if (text.isEmpty() || !innerFrame->editor()->shouldInsertText(text, range.get(), EditorInsertActionDropped)) { return false; } m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData); if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) applyCommand(ReplaceSelectionCommand::create(m_documentUnderMouse.get(), createFragmentFromText(range.get(), text), ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::MatchStyle | ReplaceSelectionCommand::PreventNesting)); } if (rootEditableElement) { if (Frame* frame = rootEditableElement->document()->frame()) frame->eventHandler()->updateDragStateAfterEditDragIfNeeded(rootEditableElement.get()); } return true; }
bool TextAutoSizingValue::adjustNodeSizes() { bool objectsRemoved = false; // Remove stale nodes. Nodes may have had their renderers detached. We'll // also need to remove the style from the documents m_textAutoSizedNodes // collection. Return true indicates we need to do that removal. Vector<RefPtr<Node> > nodesForRemoval; HashSet<RefPtr<Node> >::iterator end = m_autoSizedNodes.end(); for (HashSet<RefPtr<Node> >::iterator i = m_autoSizedNodes.begin(); i != end; ++i) { RefPtr<Node> autoSizingNode = *i; RenderText* text = static_cast<RenderText*>(autoSizingNode->renderer()); if (!text || !text->style().textSizeAdjust().isAuto() || !text->candidateComputedTextSize()) { // remove node. nodesForRemoval.append(autoSizingNode); objectsRemoved = true; } } unsigned count = nodesForRemoval.size(); for (unsigned i = 0; i < count; i++) m_autoSizedNodes.remove(nodesForRemoval[i]); // If we only have one piece of text with the style on the page don't // adjust it's size. if (m_autoSizedNodes.size() <= 1) return objectsRemoved; // Compute average size float cumulativeSize = 0; end = m_autoSizedNodes.end(); for (HashSet<RefPtr<Node> >::iterator i = m_autoSizedNodes.begin(); i != end; ++i) { RefPtr<Node> autoSizingNode = *i; RenderText* renderText = static_cast<RenderText*>(autoSizingNode->renderer()); cumulativeSize += renderText->candidateComputedTextSize(); } float averageSize = roundf(cumulativeSize / m_autoSizedNodes.size()); // Adjust sizes bool firstPass = true; end = m_autoSizedNodes.end(); for (HashSet<RefPtr<Node> >::iterator i = m_autoSizedNodes.begin(); i != end; ++i) { const RefPtr<Node>& autoSizingNode = *i; RenderText* text = static_cast<RenderText*>(autoSizingNode->renderer()); if (text && text->style().fontDescription().computedSize() != averageSize) { float specifiedSize = text->style().fontDescription().specifiedSize(); float scaleChange = averageSize / specifiedSize; if (scaleChange > MAX_SCALE_INCREASE && firstPass) { firstPass = false; averageSize = roundf(specifiedSize * MAX_SCALE_INCREASE); scaleChange = averageSize / specifiedSize; } RefPtr<RenderStyle> style = cloneRenderStyleWithState(text->style()); FontDescription fontDescription = style->fontDescription(); fontDescription.setComputedSize(averageSize); style->setFontDescription(fontDescription); style->font().update(autoSizingNode->document().ensureStyleResolver().fontSelector()); text->parent()->setStyle(style.releaseNonNull()); RenderElement* parentRenderer = text->parent(); if (parentRenderer->isAnonymousBlock()) parentRenderer = parentRenderer->parent(); // If we have a list we should resize ListMarkers separately. RenderObject* listMarkerRenderer = parentRenderer->firstChild(); if (listMarkerRenderer->isListMarker()) { RefPtr<RenderStyle> style = cloneRenderStyleWithState(listMarkerRenderer->style()); style->setFontDescription(fontDescription); style->font().update(autoSizingNode->document().ensureStyleResolver().fontSelector()); toRenderListMarker(*listMarkerRenderer).setStyle(style.releaseNonNull()); } // Resize the line height of the parent. const RenderStyle& parentStyle = parentRenderer->style(); Length lineHeightLength = parentStyle.specifiedLineHeight(); int specifiedLineHeight = 0; if (lineHeightLength.isPercent()) specifiedLineHeight = minimumValueForLength(lineHeightLength, fontDescription.specifiedSize()); else specifiedLineHeight = lineHeightLength.value(); int lineHeight = specifiedLineHeight * scaleChange; if (!lineHeightLength.isFixed() || lineHeightLength.value() != lineHeight) { RefPtr<RenderStyle> newParentStyle = cloneRenderStyleWithState(parentStyle); newParentStyle->setLineHeight(Length(lineHeight, Fixed)); newParentStyle->setSpecifiedLineHeight(lineHeightLength); newParentStyle->setFontDescription(fontDescription); newParentStyle->font().update(autoSizingNode->document().ensureStyleResolver().fontSelector()); parentRenderer->setStyle(newParentStyle.releaseNonNull()); } } } return objectsRemoved; }