Commit 9013318e authored by darin@apple.com's avatar darin@apple.com

HitTestResult should have innerNonSharedElement

https://bugs.webkit.org/show_bug.cgi?id=120579

Reviewed by Andreas Kling.

* editing/Editor.cpp:
(WebCore::Editor::copyImage): Call HitTestResult member function version of
innerNonSharedElement instead of a local function that does it.

* page/Chrome.cpp:
(WebCore::Chrome::setToolTip): Use innerNonSharedElement instead of getting
the node and checking if it's an input element. Also added some missing braces.

* page/EventHandler.cpp:
(WebCore::EventHandler::selectClosestWordFromHitTestResult): Use targetNode for
local variables instead of innerNode to match the HitTestResult function name.
(WebCore::EventHandler::selectClosestWordOrLinkFromMouseEvent): Ditto.
(WebCore::EventHandler::handleMousePressEventTripleClick): Ditto.
(WebCore::EventHandler::handleMousePressEventSingleClick): Ditto.
(WebCore::EventHandler::handleMousePressEvent): Ditto.

* rendering/HitTestResult.cpp:
(WebCore::HitTestResult::innerElement): Rewrote so there there is no loop.
(WebCore::HitTestResult::innerNonSharedElement): Ditto.

* rendering/HitTestResult.h: Added innerNonSharedElement. Generally speaking,
we'd like to avoid using Node unless there is some real need.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@154945 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent a7885f3f
2013-09-01 Darin Adler <darin@apple.com>
HitTestResult should have innerNonSharedElement
https://bugs.webkit.org/show_bug.cgi?id=120579
Reviewed by Andreas Kling.
* editing/Editor.cpp:
(WebCore::Editor::copyImage): Call HitTestResult member function version of
innerNonSharedElement instead of a local function that does it.
* page/Chrome.cpp:
(WebCore::Chrome::setToolTip): Use innerNonSharedElement instead of getting
the node and checking if it's an input element. Also added some missing braces.
* page/EventHandler.cpp:
(WebCore::EventHandler::selectClosestWordFromHitTestResult): Use targetNode for
local variables instead of innerNode to match the HitTestResult function name.
(WebCore::EventHandler::selectClosestWordOrLinkFromMouseEvent): Ditto.
(WebCore::EventHandler::handleMousePressEventTripleClick): Ditto.
(WebCore::EventHandler::handleMousePressEventSingleClick): Ditto.
(WebCore::EventHandler::handleMousePressEvent): Ditto.
* rendering/HitTestResult.cpp:
(WebCore::HitTestResult::innerElement): Rewrote so there there is no loop.
(WebCore::HitTestResult::innerNonSharedElement): Ditto.
* rendering/HitTestResult.h: Added innerNonSharedElement. Generally speaking,
we'd like to avoid using Node unless there is some real need.
2013-09-01 Xabier Rodriguez Calvar <calvaris@igalia.com>
Volume slider value should be 0 when audio is muted
......@@ -1171,20 +1171,9 @@ void Editor::copyURL(const KURL& url, const String& title, Pasteboard& pasteboar
#endif
}
// FIXME: Should this be a member function of HitTestResult?
static Element* innerNonSharedElement(const HitTestResult& result)
{
Node* node = result.innerNonSharedNode();
if (!node)
return 0;
if (node->isElementNode())
return toElement(node);
return node->parentElement();
}
void Editor::copyImage(const HitTestResult& result)
{
Element* element = innerNonSharedElement(result);
Element* element = result.innerNonSharedElement();
if (!element)
return;
......
......@@ -402,11 +402,11 @@ void Chrome::setToolTip(const HitTestResult& result)
// Next priority is a toolTip from a URL beneath the mouse (if preference is set to show those).
if (toolTip.isEmpty() && m_page->settings().showsURLsInToolTips()) {
if (Node* node = result.innerNonSharedNode()) {
if (Element* element = result.innerNonSharedElement()) {
// Get tooltip representing form action, if relevant
if (isHTMLInputElement(node)) {
HTMLInputElement* input = toHTMLInputElement(node);
if (input->isSubmitButton())
if (isHTMLInputElement(element)) {
HTMLInputElement* input = toHTMLInputElement(element);
if (input->isSubmitButton()) {
if (HTMLFormElement* form = input->form()) {
toolTip = form->action();
if (form->renderer())
......@@ -414,6 +414,7 @@ void Chrome::setToolTip(const HitTestResult& result)
else
toolTipDirection = LTR;
}
}
}
}
......@@ -435,10 +436,9 @@ void Chrome::setToolTip(const HitTestResult& result)
// Lastly, for <input type="file"> that allow multiple files, we'll consider a tooltip for the selected filenames
if (toolTip.isEmpty()) {
if (Node* node = result.innerNonSharedNode()) {
if (isHTMLInputElement(node)) {
HTMLInputElement* input = toHTMLInputElement(node);
toolTip = input->defaultToolTip();
if (Element* element = result.innerNonSharedElement()) {
if (isHTMLInputElement(element)) {
toolTip = toHTMLInputElement(element)->defaultToolTip();
// FIXME: We should obtain text direction of tooltip from
// ChromeClient or platform. As of October 2011, all client
......
......@@ -485,11 +485,11 @@ bool EventHandler::updateSelectionForMouseDownDispatchingSelectStart(Node* targe
void EventHandler::selectClosestWordFromHitTestResult(const HitTestResult& result, AppendTrailingWhitespace appendTrailingWhitespace)
{
Node* innerNode = result.targetNode();
Node* targetNode = result.targetNode();
VisibleSelection newSelection;
if (innerNode && innerNode->renderer()) {
VisiblePosition pos(innerNode->renderer()->positionForPoint(result.localPoint()));
if (targetNode && targetNode->renderer()) {
VisiblePosition pos(targetNode->renderer()->positionForPoint(result.localPoint()));
if (pos.isNotNull()) {
newSelection = VisibleSelection(pos);
newSelection.expandUsingGranularity(WordGranularity);
......@@ -498,7 +498,7 @@ void EventHandler::selectClosestWordFromHitTestResult(const HitTestResult& resul
if (appendTrailingWhitespace == ShouldAppendTrailingWhitespace && newSelection.isRange())
newSelection.appendTrailingWhitespace();
updateSelectionForMouseDownDispatchingSelectStart(innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), WordGranularity);
updateSelectionForMouseDownDispatchingSelectStart(targetNode, expandSelectionToRespectUserSelectAll(targetNode, newSelection), WordGranularity);
}
}
......@@ -515,16 +515,16 @@ void EventHandler::selectClosestWordOrLinkFromMouseEvent(const MouseEventWithHit
if (!result.hitTestResult().isLiveLink())
return selectClosestWordFromMouseEvent(result);
Node* innerNode = result.targetNode();
Node* targetNode = result.targetNode();
if (innerNode && innerNode->renderer() && m_mouseDownMayStartSelect) {
if (targetNode && targetNode->renderer() && m_mouseDownMayStartSelect) {
VisibleSelection newSelection;
Element* URLElement = result.hitTestResult().URLElement();
VisiblePosition pos(innerNode->renderer()->positionForPoint(result.localPoint()));
VisiblePosition pos(targetNode->renderer()->positionForPoint(result.localPoint()));
if (pos.isNotNull() && pos.deepEquivalent().deprecatedNode()->isDescendantOf(URLElement))
newSelection = VisibleSelection::selectionFromContentsOfNode(URLElement);
updateSelectionForMouseDownDispatchingSelectStart(innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), WordGranularity);
updateSelectionForMouseDownDispatchingSelectStart(targetNode, expandSelectionToRespectUserSelectAll(targetNode, newSelection), WordGranularity);
}
}
......@@ -551,18 +551,18 @@ bool EventHandler::handleMousePressEventTripleClick(const MouseEventWithHitTestR
if (event.event().button() != LeftButton)
return false;
Node* innerNode = event.targetNode();
if (!(innerNode && innerNode->renderer() && m_mouseDownMayStartSelect))
Node* targetNode = event.targetNode();
if (!(targetNode && targetNode->renderer() && m_mouseDownMayStartSelect))
return false;
VisibleSelection newSelection;
VisiblePosition pos(innerNode->renderer()->positionForPoint(event.localPoint()));
VisiblePosition pos(targetNode->renderer()->positionForPoint(event.localPoint()));
if (pos.isNotNull()) {
newSelection = VisibleSelection(pos);
newSelection.expandUsingGranularity(ParagraphGranularity);
}
return updateSelectionForMouseDownDispatchingSelectStart(innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), ParagraphGranularity);
return updateSelectionForMouseDownDispatchingSelectStart(targetNode, expandSelectionToRespectUserSelectAll(targetNode, newSelection), ParagraphGranularity);
}
static int textDistance(const Position& start, const Position& end)
......@@ -574,8 +574,8 @@ static int textDistance(const Position& start, const Position& end)
bool EventHandler::handleMousePressEventSingleClick(const MouseEventWithHitTestResults& event)
{
m_frame->document()->updateLayoutIgnorePendingStylesheets();
Node* innerNode = event.targetNode();
if (!(innerNode && innerNode->renderer() && m_mouseDownMayStartSelect))
Node* targetNode = event.targetNode();
if (!(targetNode && targetNode->renderer() && m_mouseDownMayStartSelect))
return false;
// Extend the selection if the Shift key is down, unless the click is in a link.
......@@ -591,16 +591,16 @@ bool EventHandler::handleMousePressEventSingleClick(const MouseEventWithHitTestR
}
}
VisiblePosition visiblePos(innerNode->renderer()->positionForPoint(event.localPoint()));
VisiblePosition visiblePos(targetNode->renderer()->positionForPoint(event.localPoint()));
if (visiblePos.isNull())
visiblePos = VisiblePosition(firstPositionInOrBeforeNode(innerNode), DOWNSTREAM);
visiblePos = VisiblePosition(firstPositionInOrBeforeNode(targetNode), DOWNSTREAM);
Position pos = visiblePos.deepEquivalent();
VisibleSelection newSelection = m_frame->selection().selection();
TextGranularity granularity = CharacterGranularity;
if (extendSelection && newSelection.isCaretOrRange()) {
VisibleSelection selectionInUserSelectAll = expandSelectionToRespectUserSelectAll(innerNode, VisibleSelection(pos));
VisibleSelection selectionInUserSelectAll = expandSelectionToRespectUserSelectAll(targetNode, VisibleSelection(pos));
if (selectionInUserSelectAll.isRange()) {
if (comparePositions(selectionInUserSelectAll.start(), newSelection.start()) < 0)
pos = selectionInUserSelectAll.start();
......@@ -627,9 +627,9 @@ bool EventHandler::handleMousePressEventSingleClick(const MouseEventWithHitTestR
newSelection.expandUsingGranularity(m_frame->selection().granularity());
}
} else
newSelection = expandSelectionToRespectUserSelectAll(innerNode, visiblePos);
newSelection = expandSelectionToRespectUserSelectAll(targetNode, visiblePos);
bool handled = updateSelectionForMouseDownDispatchingSelectStart(innerNode, newSelection, granularity);
bool handled = updateSelectionForMouseDownDispatchingSelectStart(targetNode, newSelection, granularity);
if (event.event().button() == MiddleButton) {
// Ignore handled, since we want to paste to where the caret was placed anyway.
......@@ -696,9 +696,7 @@ bool EventHandler::handleMousePressEvent(const MouseEventWithHitTestResults& eve
if (singleClick)
focusDocumentView();
Node* innerNode = event.targetNode();
m_mousePressNode = innerNode;
m_mousePressNode = event.targetNode();
#if ENABLE(DRAG_SUPPORT)
m_dragStartPos = event.event().position();
#endif
......
......@@ -690,12 +690,22 @@ Node* HitTestResult::targetNode() const
Element* HitTestResult::innerElement() const
{
for (Node* node = m_innerNode.get(); node; node = node->parentNode()) {
if (node->isElementNode())
return toElement(node);
}
Node* node = m_innerNode.get();
if (!node)
return 0;
if (node->isElementNode())
return toElement(node);
return node->parentElement();
}
return 0;
Element* HitTestResult::innerNonSharedElement() const
{
Node* node = m_innerNonSharedNode.get();
if (!node)
return 0;
if (node->isElementNode())
return toElement(node);
return node->parentElement();
}
} // namespace WebCore
......@@ -62,6 +62,7 @@ public:
Node* innerNode() const { return m_innerNode.get(); }
Element* innerElement() const;
Node* innerNonSharedNode() const { return m_innerNonSharedNode.get(); }
Element* innerNonSharedElement() const;
Element* URLElement() const { return m_innerURLElement.get(); }
Scrollbar* scrollbar() const { return m_scrollbar.get(); }
bool isOverWidget() const { return m_isOverWidget; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment