From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/WebKit2/Shared/WebRenderObject.cpp | 86 +++++++++++++++++-------------- 1 file changed, 47 insertions(+), 39 deletions(-) (limited to 'Source/WebKit2/Shared/WebRenderObject.cpp') diff --git a/Source/WebKit2/Shared/WebRenderObject.cpp b/Source/WebKit2/Shared/WebRenderObject.cpp index 3b44988a8..afc4336ed 100644 --- a/Source/WebKit2/Shared/WebRenderObject.cpp +++ b/Source/WebKit2/Shared/WebRenderObject.cpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include #include #include @@ -40,95 +42,101 @@ using namespace WebCore; namespace WebKit { -PassRefPtr WebRenderObject::create(WebPage* page) +RefPtr WebRenderObject::create(WebPage* page) { Frame* mainFrame = page->mainFrame(); if (!mainFrame) - return 0; + return nullptr; if (!mainFrame->loader().client().hasHTMLView()) - return 0; + return nullptr; RenderView* contentRenderer = mainFrame->contentRenderer(); if (!contentRenderer) - return 0; + return nullptr; return adoptRef(new WebRenderObject(contentRenderer, true)); } -PassRefPtr WebRenderObject::create(const String& name, const String& elementTagName, const String& elementID, PassRefPtr elementClassNames, WebCore::IntPoint absolutePosition, WebCore::IntRect frameRect, PassRefPtr children) +PassRefPtr WebRenderObject::create(const String& name, const String& elementTagName, const String& elementID, PassRefPtr elementClassNames, WebCore::IntPoint absolutePosition, WebCore::IntRect frameRect, const String& textSnippet, unsigned textLength, PassRefPtr children) { - return adoptRef(new WebRenderObject(name, elementTagName, elementID, elementClassNames, absolutePosition, frameRect, children)); + return adoptRef(new WebRenderObject(name, elementTagName, elementID, elementClassNames, absolutePosition, frameRect, textSnippet, textLength, children)); } WebRenderObject::WebRenderObject(RenderObject* renderer, bool shouldIncludeDescendants) { m_name = renderer->renderName(); + m_textLength = 0; if (Node* node = renderer->node()) { - if (node->isElementNode()) { - Element* element = toElement(node); - m_elementTagName = element->tagName(); - m_elementID = element->getIdAttribute(); + if (is(*node)) { + Element& element = downcast(*node); + m_elementTagName = element.tagName(); + m_elementID = element.getIdAttribute(); - if (element->isStyledElement() && element->hasClass()) { + if (element.isStyledElement() && element.hasClass()) { Vector> classNames; - classNames.reserveInitialCapacity(element->classNames().size()); + classNames.reserveInitialCapacity(element.classNames().size()); - for (size_t i = 0, size = element->classNames().size(); i < size; ++i) - classNames.append(API::String::create(element->classNames()[i])); + for (size_t i = 0, size = element.classNames().size(); i < size; ++i) + classNames.append(API::String::create(element.classNames()[i])); - m_elementClassNames = API::Array::create(std::move(classNames)); + m_elementClassNames = API::Array::create(WTFMove(classNames)); } } + + if (node->isTextNode()) { + String value = node->nodeValue(); + m_textLength = value.length(); + + const int maxSnippetLength = 40; + if (value.length() > maxSnippetLength) + m_textSnippet = value.substring(0, maxSnippetLength); + else + m_textSnippet = value; + } } // FIXME: broken with transforms m_absolutePosition = flooredIntPoint(renderer->localToAbsolute()); - if (renderer->isBox()) - m_frameRect = toRenderBox(renderer)->pixelSnappedFrameRect(); - else if (renderer->isText()) { - m_frameRect = toRenderText(renderer)->linesBoundingBox(); - m_frameRect.setX(toRenderText(renderer)->firstRunX()); - m_frameRect.setY(toRenderText(renderer)->firstRunY()); - } else if (renderer->isRenderInline()) - m_frameRect = toRenderBoxModelObject(renderer)->borderBoundingBox(); + if (is(*renderer)) + m_frameRect = snappedIntRect(downcast(*renderer).frameRect()); + else if (is(*renderer)) { + m_frameRect = downcast(*renderer).linesBoundingBox(); + m_frameRect.setLocation(downcast(*renderer).firstRunLocation()); + } else if (is(*renderer)) + m_frameRect = IntRect(downcast(*renderer).borderBoundingBox()); if (!shouldIncludeDescendants) return; Vector> children; - for (RenderObject* coreChild = renderer->firstChildSlow(); coreChild; coreChild = coreChild->nextSibling()) { - RefPtr child = adoptRef(new WebRenderObject(coreChild, shouldIncludeDescendants)); - children.append(std::move(child)); - } - - if (renderer->isWidget()) { - if (Widget* widget = toRenderWidget(renderer)->widget()) { - if (widget->isFrameView()) { - FrameView* frameView = toFrameView(widget); - if (RenderView* coreContentRenderer = frameView->frame().contentRenderer()) { - RefPtr contentRenderer = adoptRef(new WebRenderObject(coreContentRenderer, shouldIncludeDescendants)); + for (auto* coreChild = renderer->firstChildSlow(); coreChild; coreChild = coreChild->nextSibling()) + children.append(adoptRef(*new WebRenderObject(coreChild, shouldIncludeDescendants))); - children.append(std::move(contentRenderer)); - } - } + if (is(*renderer)) { + auto* widget = downcast(*renderer).widget(); + if (is(widget)) { + if (auto* coreContentRenderer = downcast(*widget).frame().contentRenderer()) + children.append(adoptRef(*new WebRenderObject(coreContentRenderer, shouldIncludeDescendants))); } } - m_children = API::Array::create(std::move(children)); + m_children = API::Array::create(WTFMove(children)); } -WebRenderObject::WebRenderObject(const String& name, const String& elementTagName, const String& elementID, PassRefPtr elementClassNames, WebCore::IntPoint absolutePosition, WebCore::IntRect frameRect, PassRefPtr children) +WebRenderObject::WebRenderObject(const String& name, const String& elementTagName, const String& elementID, PassRefPtr elementClassNames, WebCore::IntPoint absolutePosition, WebCore::IntRect frameRect, const String& textSnippet, unsigned textLength, PassRefPtr children) : m_children(children) , m_name(name) , m_elementTagName(elementTagName) , m_elementID(elementID) + , m_textSnippet(textSnippet) , m_elementClassNames(elementClassNames) , m_absolutePosition(absolutePosition) , m_frameRect(frameRect) + , m_textLength(textLength) { } -- cgit v1.2.1