Modified: trunk/Source/WebCore/ChangeLog (154944 => 154945)
--- trunk/Source/WebCore/ChangeLog 2013-09-01 17:12:16 UTC (rev 154944)
+++ trunk/Source/WebCore/ChangeLog 2013-09-01 19:12:31 UTC (rev 154945)
@@ -1,3 +1,33 @@
+2013-09-01 Darin Adler <[email protected]>
+
+ 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 <[email protected]>
Volume slider value should be 0 when audio is muted
Modified: trunk/Source/WebCore/editing/Editor.cpp (154944 => 154945)
--- trunk/Source/WebCore/editing/Editor.cpp 2013-09-01 17:12:16 UTC (rev 154944)
+++ trunk/Source/WebCore/editing/Editor.cpp 2013-09-01 19:12:31 UTC (rev 154945)
@@ -1171,20 +1171,9 @@
#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;
Modified: trunk/Source/WebCore/page/Chrome.cpp (154944 => 154945)
--- trunk/Source/WebCore/page/Chrome.cpp 2013-09-01 17:12:16 UTC (rev 154944)
+++ trunk/Source/WebCore/page/Chrome.cpp 2013-09-01 19:12:31 UTC (rev 154945)
@@ -402,11 +402,11 @@
// 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 @@
else
toolTipDirection = LTR;
}
+ }
}
}
@@ -435,10 +436,9 @@
// 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
Modified: trunk/Source/WebCore/page/EventHandler.cpp (154944 => 154945)
--- trunk/Source/WebCore/page/EventHandler.cpp 2013-09-01 17:12:16 UTC (rev 154944)
+++ trunk/Source/WebCore/page/EventHandler.cpp 2013-09-01 19:12:31 UTC (rev 154945)
@@ -485,11 +485,11 @@
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 @@
if (appendTrailingWhitespace == ShouldAppendTrailingWhitespace && newSelection.isRange())
newSelection.appendTrailingWhitespace();
- updateSelectionForMouseDownDispatchingSelectStart(innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), WordGranularity);
+ updateSelectionForMouseDownDispatchingSelectStart(targetNode, expandSelectionToRespectUserSelectAll(targetNode, newSelection), WordGranularity);
}
}
@@ -515,16 +515,16 @@
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 @@
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 @@
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 @@
}
}
- 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 @@
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 @@
if (singleClick)
focusDocumentView();
- Node* innerNode = event.targetNode();
-
- m_mousePressNode = innerNode;
+ m_mousePressNode = event.targetNode();
#if ENABLE(DRAG_SUPPORT)
m_dragStartPos = event.event().position();
#endif
Modified: trunk/Source/WebCore/rendering/HitTestResult.cpp (154944 => 154945)
--- trunk/Source/WebCore/rendering/HitTestResult.cpp 2013-09-01 17:12:16 UTC (rev 154944)
+++ trunk/Source/WebCore/rendering/HitTestResult.cpp 2013-09-01 19:12:31 UTC (rev 154945)
@@ -690,12 +690,22 @@
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
Modified: trunk/Source/WebCore/rendering/HitTestResult.h (154944 => 154945)
--- trunk/Source/WebCore/rendering/HitTestResult.h 2013-09-01 17:12:16 UTC (rev 154944)
+++ trunk/Source/WebCore/rendering/HitTestResult.h 2013-09-01 19:12:31 UTC (rev 154945)
@@ -62,6 +62,7 @@
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; }