This repository has been archived by the owner on Apr 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not show a tooltip same as the previous one.
If a tooltip is closed by a keyboard event and the mouse cursor was not moved, the same tooltip was shown again after some delay only on Windows. Blink receives native mousemove events repeatedly on Windows even if the mouse cursor is not moved. ChromeClient saves the last tooltip string and the last mouse position, and do not call virtual setToolTip() if they are not changed. This CL not only fixes the bug, but also reduces unnecessary IPC messages for tooltip. BUG=557660 TEST=automated Review URL: https://codereview.chromium.org/1500813004 Cr-Commit-Position: refs/heads/master@{#363174} (cherry picked from commit 91db68e) Review URL: https://codereview.chromium.org/1504743002 . Cr-Commit-Position: refs/branch-heads/2564@{#248} Cr-Branched-From: 1283eca-refs/heads/master@{#359700}
- Loading branch information
1 parent
ae05498
commit 7d44e9f
Showing
5 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "config.h" | ||
#include "core/page/ChromeClient.h" | ||
|
||
#include "core/dom/Document.h" | ||
#include "core/layout/HitTestResult.h" | ||
#include "core/loader/EmptyClients.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
namespace blink { | ||
|
||
namespace { | ||
|
||
class ChromeClientToolTipLogger : public EmptyChromeClient { | ||
public: | ||
void setToolTip(const String& text, TextDirection) override | ||
{ | ||
m_toolTipForLastSetToolTip = text; | ||
} | ||
|
||
String toolTipForLastSetToolTip() const { return m_toolTipForLastSetToolTip; } | ||
void clearToolTipForLastSetToolTip() { m_toolTipForLastSetToolTip = String(); } | ||
|
||
private: | ||
String m_toolTipForLastSetToolTip; | ||
}; | ||
|
||
} // anonymous namespace | ||
|
||
class ChromeClientTest : public testing::Test { | ||
}; | ||
|
||
TEST_F(ChromeClientTest, SetToolTipFlood) | ||
{ | ||
ChromeClientToolTipLogger logger; | ||
ChromeClient* client = &logger; | ||
HitTestResult result(HitTestRequest(HitTestRequest::Move), LayoutPoint(10, 20)); | ||
RefPtrWillBeRawPtr<Document> doc = Document::create(); | ||
RefPtrWillBeRawPtr<Element> element = HTMLElement::create(HTMLNames::divTag, *doc); | ||
element->setAttribute(HTMLNames::titleAttr, "tooltip"); | ||
result.setInnerNode(element.get()); | ||
|
||
client->setToolTip(result); | ||
EXPECT_EQ("tooltip", logger.toolTipForLastSetToolTip()); | ||
|
||
// seToolTip(HitTestResult) again in the same condition. | ||
logger.clearToolTipForLastSetToolTip(); | ||
client->setToolTip(result); | ||
// setToolTip(String,TextDirection) should not be called. | ||
EXPECT_EQ(String(), logger.toolTipForLastSetToolTip()); | ||
|
||
// Cancel the tooltip, and setToolTip(HitTestResult) again. | ||
client->clearToolTip(); | ||
logger.clearToolTipForLastSetToolTip(); | ||
client->setToolTip(result); | ||
// setToolTip(String,TextDirection) should not be called. | ||
EXPECT_EQ(String(), logger.toolTipForLastSetToolTip()); | ||
|
||
logger.clearToolTipForLastSetToolTip(); | ||
element->setAttribute(HTMLNames::titleAttr, "updated"); | ||
client->setToolTip(result); | ||
// setToolTip(String,TextDirection) should be called because tooltip string | ||
// is different from the last one. | ||
EXPECT_EQ("updated", logger.toolTipForLastSetToolTip()); | ||
} | ||
|
||
} // namespace blink |