Commit 5092c26c authored by vasilii's avatar vasilii Committed by Commit bot

The Password bubble should fade out when user types in the input fields on the web page.

BUG=394287

Review URL: https://codereview.chromium.org/541683003

Cr-Commit-Position: refs/heads/master@{#293899}
parent bd330a25
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/browser/ui/views/passwords/manage_password_item_view.h" #include "chrome/browser/ui/views/passwords/manage_password_item_view.h"
#include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -636,37 +637,56 @@ void ManagePasswordsBubbleView::SaveConfirmationView::ButtonPressed( ...@@ -636,37 +637,56 @@ void ManagePasswordsBubbleView::SaveConfirmationView::ButtonPressed(
// ManagePasswordsBubbleView::WebContentMouseHandler -------------------------- // ManagePasswordsBubbleView::WebContentMouseHandler --------------------------
// The class listens for WebContentsView events and notifies the bubble if the // The class listens for WebContentsView events and notifies the bubble if the
// view was clicked on. // view was clicked on or received keystrokes.
class ManagePasswordsBubbleView::WebContentMouseHandler class ManagePasswordsBubbleView::WebContentMouseHandler
: public ui::EventHandler { : public ui::EventHandler {
public: public:
explicit WebContentMouseHandler(ManagePasswordsBubbleView* bubble) explicit WebContentMouseHandler(ManagePasswordsBubbleView* bubble);
: bubble_(bubble) { virtual ~WebContentMouseHandler();
GetWebContentsWindow()->AddPreTargetHandler(this);
}
virtual ~WebContentMouseHandler() {
aura::Window* window = GetWebContentsWindow();
if (window)
window->RemovePreTargetHandler(this);
}
virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
if (event->type() == ui::ET_MOUSE_PRESSED) virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
bubble_->StartFadingOut();
}
private: private:
aura::Window* GetWebContentsWindow() { aura::Window* GetWebContentsWindow();
content::WebContents* web_contents = bubble_->model()->web_contents();
return web_contents ? web_contents->GetNativeView() : NULL;
}
ManagePasswordsBubbleView* bubble_; ManagePasswordsBubbleView* bubble_;
DISALLOW_COPY_AND_ASSIGN(WebContentMouseHandler); DISALLOW_COPY_AND_ASSIGN(WebContentMouseHandler);
}; };
ManagePasswordsBubbleView::WebContentMouseHandler::WebContentMouseHandler(
ManagePasswordsBubbleView* bubble)
: bubble_(bubble) {
GetWebContentsWindow()->AddPreTargetHandler(this);
}
ManagePasswordsBubbleView::WebContentMouseHandler::~WebContentMouseHandler() {
if (aura::Window* window = GetWebContentsWindow())
window->RemovePreTargetHandler(this);
}
void ManagePasswordsBubbleView::WebContentMouseHandler::OnKeyEvent(
ui::KeyEvent* event) {
content::WebContents* web_contents = bubble_->model()->web_contents();
content::RenderViewHost* rvh = web_contents->GetRenderViewHost();
if (rvh->IsFocusedElementEditable() &&
event->type() == ui::ET_KEY_PRESSED)
bubble_->StartFadingOut();
}
void ManagePasswordsBubbleView::WebContentMouseHandler::OnMouseEvent(
ui::MouseEvent* event) {
if (event->type() == ui::ET_MOUSE_PRESSED)
bubble_->StartFadingOut();
}
aura::Window*
ManagePasswordsBubbleView::WebContentMouseHandler::GetWebContentsWindow() {
content::WebContents* web_contents = bubble_->model()->web_contents();
return web_contents ? web_contents->GetNativeView() : NULL;
}
// ManagePasswordsBubbleView::FadeOutObserver --------------------------------- // ManagePasswordsBubbleView::FadeOutObserver ---------------------------------
// The class notifies the bubble when it faded out completely. // The class notifies the bubble when it faded out completely.
......
...@@ -23,36 +23,43 @@ namespace { ...@@ -23,36 +23,43 @@ namespace {
const char kDisplayDispositionMetric[] = "PasswordBubble.DisplayDisposition"; const char kDisplayDispositionMetric[] = "PasswordBubble.DisplayDisposition";
// Listens to WebContents and invokes a callback on the mouse down event. // Listens to WebContents and invokes a callback on the mouse/key down event.
class WebContentMouseClickHandler : public ui::EventHandler { class WebContentEventHandler : public ui::EventHandler {
public: public:
explicit WebContentMouseClickHandler(content::WebContents* web_contents, explicit WebContentEventHandler(content::WebContents* web_contents,
const base::Closure& callback) const base::Closure& callback)
: web_contents_(web_contents), : web_contents_(web_contents),
callback_(callback), callback_(callback),
was_called_(false) { was_called_(false) {
web_contents_->GetNativeView()->AddPreTargetHandler(this); web_contents_->GetNativeView()->AddPreTargetHandler(this);
} }
virtual ~WebContentMouseClickHandler() { virtual ~WebContentEventHandler() {
web_contents_->GetNativeView()->RemovePreTargetHandler(this); web_contents_->GetNativeView()->RemovePreTargetHandler(this);
} }
virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE {
if (event->type() == ui::ET_KEY_PRESSED)
HandleEvent(event);
}
virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
if (event->type() == ui::ET_MOUSE_PRESSED) { if (event->type() == ui::ET_MOUSE_PRESSED)
callback_.Run(); HandleEvent(event);
was_called_ = true;
}
} }
bool was_called() const { return was_called_; } bool was_called() const { return was_called_; }
private: private:
void HandleEvent(ui::Event* event) {
callback_.Run();
was_called_ = true;
}
content::WebContents* web_contents_; content::WebContents* web_contents_;
base::Closure callback_; base::Closure callback_;
bool was_called_; bool was_called_;
DISALLOW_COPY_AND_ASSIGN(WebContentMouseClickHandler); DISALLOW_COPY_AND_ASSIGN(WebContentEventHandler);
}; };
void CheckBubbleAnimation() { void CheckBubbleAnimation() {
...@@ -230,9 +237,30 @@ IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, FadeOnClick) { ...@@ -230,9 +237,30 @@ IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, FadeOnClick) {
GetFocusManager()->GetFocusedView()); GetFocusManager()->GetFocusedView());
// We have to check the animation in the process of handling the mouse down // We have to check the animation in the process of handling the mouse down
// event. Otherwise, animation may finish too quickly. // event. Otherwise, animation may finish too quickly.
WebContentMouseClickHandler observer( WebContentEventHandler observer(
browser()->tab_strip_model()->GetActiveWebContents(), browser()->tab_strip_model()->GetActiveWebContents(),
base::Bind(&CheckBubbleAnimation)); base::Bind(&CheckBubbleAnimation));
ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
EXPECT_TRUE(observer.was_called()); EXPECT_TRUE(observer.was_called());
} }
IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, FadeOnKey) {
ui_test_utils::NavigateToURL(
browser(),
GURL("data:text/html;charset=utf-8,<input type=\"text\" autofocus>"));
ManagePasswordsBubbleView::ShowBubble(
browser()->tab_strip_model()->GetActiveWebContents(),
ManagePasswordsBubble::AUTOMATIC);
EXPECT_TRUE(ManagePasswordsBubbleView::IsShowing());
EXPECT_FALSE(ManagePasswordsBubbleView::manage_password_bubble()->
GetFocusManager()->GetFocusedView());
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
// We have to check the animation in the process of handling the key down
// event. Otherwise, animation may finish too quickly.
WebContentEventHandler observer(
browser()->tab_strip_model()->GetActiveWebContents(),
base::Bind(&CheckBubbleAnimation));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_K,
false, false, false, false));
EXPECT_TRUE(observer.was_called());
}
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