Commit bef9a565 authored by pritam.nikam's avatar pritam.nikam Committed by Commit bot

[Password Manager] Close the bubble when full screen state gets change.

BUG=425993

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

Cr-Commit-Position: refs/heads/master@{#309613}
parent 45b09e88
......@@ -9,6 +9,7 @@
#include "base/gtest_prod_util.h"
#include "base/timer/timer.h"
#include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
#include "chrome/browser/ui/views/managed_full_screen_bubble_delegate_view.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_icon_image.h"
......@@ -29,9 +30,8 @@ class ImageButton;
} // namespace views
// View used to display the zoom percentage when it has changed.
class ZoomBubbleView : public views::BubbleDelegateView,
class ZoomBubbleView : public ManagedFullScreenBubbleDelegateView,
public views::ButtonListener,
public content::NotificationObserver,
public ImmersiveModeController::Observer,
public extensions::IconImage::Observer {
public:
......@@ -79,18 +79,28 @@ class ZoomBubbleView : public views::BubbleDelegateView,
FullscreenController* fullscreen_controller);
~ZoomBubbleView() override;
// If the bubble is not anchored to a view, places the bubble in the top
// right (left in RTL) of the |screen_bounds| that contain |web_contents_|'s
// browser window. Because the positioning is based on the size of the
// bubble, this must be called after the bubble is created.
void AdjustForFullscreen(const gfx::Rect& screen_bounds);
// ManagedFullScreenBubbleDelegateView:
void OnGestureEvent(ui::GestureEvent* event) override;
void OnMouseEntered(const ui::MouseEvent& event) override;
void OnMouseExited(const ui::MouseEvent& event) override;
void Init() override;
void WindowClosing() override;
void Close() override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// ImmersiveModeController::Observer:
void OnImmersiveRevealStarted() override;
void OnImmersiveModeControllerDestroyed() override;
// extensions::IconImage::Observer:
void OnExtensionIconImageChanged(extensions::IconImage* /* image */) override;
// Refreshes the bubble by changing the zoom percentage appropriately and
// resetting the timer if necessary.
void Refresh();
void Close();
// Sets information about the extension that initiated the zoom change.
// Calling this method asserts that the extension |extension| did initiate
// the zoom change.
......@@ -102,32 +112,6 @@ class ZoomBubbleView : public views::BubbleDelegateView,
// Stops the auto-close timer.
void StopTimer();
// extensions::IconImage::Observer overrides:
void OnExtensionIconImageChanged(extensions::IconImage* /* image */) override;
// views::View methods.
void OnMouseEntered(const ui::MouseEvent& event) override;
void OnMouseExited(const ui::MouseEvent& event) override;
// ui::EventHandler method.
void OnGestureEvent(ui::GestureEvent* event) override;
// views::ButtonListener method.
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// views::BubbleDelegateView method.
void Init() override;
void WindowClosing() override;
// content::NotificationObserver method.
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
// ImmersiveModeController::Observer methods.
void OnImmersiveRevealStarted() override;
void OnImmersiveModeControllerDestroyed() override;
ZoomBubbleExtensionInfo extension_info_;
// Singleton instance of the zoom bubble. The zoom bubble can only be shown on
......@@ -157,9 +141,6 @@ class ZoomBubbleView : public views::BubbleDelegateView,
// Not owned.
ImmersiveModeController* immersive_mode_controller_;
// Used to register for fullscreen change notifications.
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(ZoomBubbleView);
};
......
// Copyright 2014 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 "chrome/browser/ui/views/managed_full_screen_bubble_delegate_view.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
#include "content/public/browser/notification_source.h"
#include "ui/gfx/geometry/rect.h"
ManagedFullScreenBubbleDelegateView::ManagedFullScreenBubbleDelegateView(
views::View* anchor_view,
content::WebContents* web_contents)
: BubbleDelegateView(
anchor_view,
anchor_view ?
views::BubbleBorder::TOP_RIGHT : views::BubbleBorder::NONE) {
// Add observer to close the bubble if the fullscreen state changes.
if (web_contents) {
Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
registrar_.Add(this, chrome::NOTIFICATION_FULLSCREEN_CHANGED,
content::Source<FullscreenController>(
browser->fullscreen_controller()));
}
}
ManagedFullScreenBubbleDelegateView::~ManagedFullScreenBubbleDelegateView() {
}
void ManagedFullScreenBubbleDelegateView::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type);
GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE);
Close();
}
void ManagedFullScreenBubbleDelegateView::Close() {
GetWidget()->Close();
}
void ManagedFullScreenBubbleDelegateView::AdjustForFullscreen(
const gfx::Rect& screen_bounds) {
if (GetAnchorView())
return;
const int kBubblePaddingFromScreenEdge = 20;
int bubble_half_width = width() / 2;
const int x_pos = base::i18n::IsRTL() ?
(screen_bounds.x() + bubble_half_width + kBubblePaddingFromScreenEdge) :
(screen_bounds.right() - bubble_half_width -
kBubblePaddingFromScreenEdge);
SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0));
}
// Copyright 2014 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.
#ifndef CHROME_BROWSER_UI_VIEWS_MANAGED_FULL_SCREEN_BUBBLE_DELEGATE_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_MANAGED_FULL_SCREEN_BUBBLE_DELEGATE_VIEW_H_
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/views/bubble/bubble_delegate.h"
namespace content {
class NotificationDetails;
class NotificationSource;
class WebContents;
};
// View used to automatically close a bubble when the browser transitions in or
// out of fullscreen mode.
class ManagedFullScreenBubbleDelegateView
: public views::BubbleDelegateView,
public content::NotificationObserver {
public:
ManagedFullScreenBubbleDelegateView(views::View* anchor_view,
content::WebContents* web_contents);
~ManagedFullScreenBubbleDelegateView() override;
// content::NotificationObserver:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
protected:
// Closes the bubble.
virtual void Close();
// If the bubble is not anchored to a view, places the bubble in the top right
// (left in RTL) of the |screen_bounds| that contain web contents's browser
// window. Because the positioning is based on the size of the bubble, this
// must be called after the bubble is created.
void AdjustForFullscreen(const gfx::Rect& screen_bounds);
private:
// Used to register for fullscreen change notifications.
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(ManagedFullScreenBubbleDelegateView);
};
#endif // CHROME_BROWSER_UI_VIEWS_MANAGED_FULL_SCREEN_BUBBLE_DELEGATE_VIEW_H_
......@@ -4,21 +4,18 @@
#include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
#include "chrome/browser/ui/passwords/save_password_refusal_combobox_model.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/passwords/credentials_item_view.h"
#include "chrome/browser/ui/views/passwords/manage_password_items_view.h"
#include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/views/controls/button/blue_button.h"
......@@ -989,9 +986,7 @@ ManagePasswordsBubbleView::ManagePasswordsBubbleView(
ManagePasswordsIconView* anchor_view,
DisplayReason reason)
: ManagePasswordsBubble(web_contents, reason),
BubbleDelegateView(anchor_view,
anchor_view ? views::BubbleBorder::TOP_RIGHT
: views::BubbleBorder::NONE),
ManagedFullScreenBubbleDelegateView(anchor_view, web_contents),
anchor_view_(anchor_view),
initially_focused_view_(NULL) {
// Compensate for built-in vertical padding in the anchor view's image.
......@@ -999,13 +994,6 @@ ManagePasswordsBubbleView::ManagePasswordsBubbleView(
if (anchor_view)
anchor_view->SetActive(true);
mouse_handler_.reset(new WebContentMouseHandler(this));
// Add observers to close the bubble if the fullscreen state changes.
Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
registrar_.Add(
this,
chrome::NOTIFICATION_FULLSCREEN_CHANGED,
content::Source<FullscreenController>(browser->fullscreen_controller()));
}
ManagePasswordsBubbleView::~ManagePasswordsBubbleView() {
......@@ -1013,23 +1001,27 @@ ManagePasswordsBubbleView::~ManagePasswordsBubbleView() {
anchor_view_->SetActive(false);
}
void ManagePasswordsBubbleView::AdjustForFullscreen(
const gfx::Rect& screen_bounds) {
if (GetAnchorView())
return;
views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() {
return initially_focused_view_;
}
void ManagePasswordsBubbleView::Init() {
views::FillLayout* layout = new views::FillLayout();
SetLayoutManager(layout);
Refresh();
}
// The bubble's padding from the screen edge, used in fullscreen.
const int kFullscreenPaddingEnd = 20;
const size_t bubble_half_width = width() / 2;
const int x_pos = base::i18n::IsRTL() ?
screen_bounds.x() + bubble_half_width + kFullscreenPaddingEnd :
screen_bounds.right() - bubble_half_width - kFullscreenPaddingEnd;
SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0));
void ManagePasswordsBubbleView::WindowClosing() {
// Close() closes the window asynchronously, so by the time we reach here,
// |manage_passwords_bubble_| may have already been reset.
if (manage_passwords_bubble_ == this)
manage_passwords_bubble_ = NULL;
}
void ManagePasswordsBubbleView::Close() {
mouse_handler_.reset();
GetWidget()->Close();
ManagedFullScreenBubbleDelegateView::Close();
}
void ManagePasswordsBubbleView::Refresh() {
......@@ -1061,16 +1053,6 @@ void ManagePasswordsBubbleView::Refresh() {
SizeToContents();
}
void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() {
if (model()->best_matches().empty()) {
// Skip confirmation if there are no existing passwords for this site.
NotifyConfirmedNeverForThisSite();
} else {
model()->OnConfirmationForNeverForThisSite();
Refresh();
}
}
void ManagePasswordsBubbleView::NotifyConfirmedNeverForThisSite() {
model()->OnNeverForThisSiteClicked();
Close();
......@@ -1081,29 +1063,12 @@ void ManagePasswordsBubbleView::NotifyUndoNeverForThisSite() {
Refresh();
}
void ManagePasswordsBubbleView::Init() {
views::FillLayout* layout = new views::FillLayout();
SetLayoutManager(layout);
Refresh();
}
void ManagePasswordsBubbleView::WindowClosing() {
// Close() closes the window asynchronously, so by the time we reach here,
// |manage_passwords_bubble_| may have already been reset.
if (manage_passwords_bubble_ == this)
manage_passwords_bubble_ = NULL;
}
views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() {
return initially_focused_view_;
}
void ManagePasswordsBubbleView::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED);
GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE);
CloseBubble();
void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() {
if (model()->best_matches().empty()) {
// Skip confirmation if there are no existing passwords for this site.
NotifyConfirmedNeverForThisSite();
} else {
model()->OnConfirmationForNeverForThisSite();
Refresh();
}
}
......@@ -6,9 +6,7 @@
#define CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_VIEW_H_
#include "chrome/browser/ui/passwords/manage_passwords_bubble.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/views/bubble/bubble_delegate.h"
#include "chrome/browser/ui/views/managed_full_screen_bubble_delegate_view.h"
class ManagePasswordsIconView;
......@@ -25,8 +23,7 @@ class WebContents;
// 3. BlacklistedView: Informs the user that the current page is blacklisted.
//
class ManagePasswordsBubbleView : public ManagePasswordsBubble,
public views::BubbleDelegateView,
public content::NotificationObserver {
public ManagedFullScreenBubbleDelegateView {
public:
// Shows the bubble.
static void ShowBubble(content::WebContents* web_contents,
......@@ -61,20 +58,18 @@ class ManagePasswordsBubbleView : public ManagePasswordsBubble,
class PendingView;
class SaveConfirmationView;
class SetupOSPasswordView;
class WebContentMouseHandler;
ManagePasswordsBubbleView(content::WebContents* web_contents,
ManagePasswordsIconView* anchor_view,
DisplayReason reason);
~ManagePasswordsBubbleView() override;
// If the bubble is not anchored to a view, places the bubble in the top
// right (left in RTL) of the |screen_bounds| that contain |web_contents_|'s
// browser window. Because the positioning is based on the size of the
// bubble, this must be called after the bubble is created.
void AdjustForFullscreen(const gfx::Rect& screen_bounds);
// Close the bubble.
void Close();
// ManagedFullScreenBubbleDelegateView:
views::View* GetInitiallyFocusedView() override;
void Init() override;
void WindowClosing() override;
void Close() override;
// Refreshes the bubble's state: called to display a confirmation screen after
// a user selects "Never for this site", for instance.
......@@ -92,18 +87,6 @@ class ManagePasswordsBubbleView : public ManagePasswordsBubble,
// undo the action and refresh to PendingView.
void NotifyUndoNeverForThisSite();
// views::BubbleDelegateView:
void Init() override;
void WindowClosing() override;
// views::WidgetDelegate:
views::View* GetInitiallyFocusedView() override;
// content::NotificationObserver:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
void set_initially_focused_view(views::View* view) {
DCHECK(!initially_focused_view_);
initially_focused_view_ = view;
......@@ -120,12 +103,8 @@ class ManagePasswordsBubbleView : public ManagePasswordsBubble,
views::View* initially_focused_view_;
// A helper to intercept mouse click events on the web contents.
class WebContentMouseHandler;
scoped_ptr<WebContentMouseHandler> mouse_handler_;
// Used to register for fullscreen change notifications.
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleView);
};
......
......@@ -258,7 +258,7 @@ TranslateBubbleView::TranslateBubbleView(
scoped_ptr<TranslateBubbleModel> model,
translate::TranslateErrors::Type error_type,
content::WebContents* web_contents)
: BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
: ManagedFullScreenBubbleDelegateView(anchor_view, web_contents),
WebContentsObserver(web_contents),
before_translate_view_(NULL),
translating_view_(NULL),
......
......@@ -12,9 +12,9 @@
#include "chrome/browser/translate/chrome_translate_client.h"
#include "chrome/browser/ui/translate/language_combobox_model.h"
#include "chrome/browser/ui/translate/translate_bubble_model.h"
#include "chrome/browser/ui/views/managed_full_screen_bubble_delegate_view.h"
#include "components/translate/core/common/translate_errors.h"
#include "content/public/browser/web_contents_observer.h"
#include "ui/views/bubble/bubble_delegate.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/combobox/combobox_listener.h"
#include "ui/views/controls/link_listener.h"
......@@ -33,7 +33,7 @@ namespace ui {
class SimpleComboboxModel;
}
class TranslateBubbleView : public views::BubbleDelegateView,
class TranslateBubbleView : public ManagedFullScreenBubbleDelegateView,
public views::ButtonListener,
public views::ComboboxListener,
public views::LinkListener,
......
......@@ -2210,6 +2210,8 @@
'browser/ui/views/login_prompt_views.cc',
'browser/ui/views/login_view.cc',
'browser/ui/views/login_view.h',
'browser/ui/views/managed_full_screen_bubble_delegate_view.cc',
'browser/ui/views/managed_full_screen_bubble_delegate_view.h',
'browser/ui/views/omnibox/omnibox_popup_contents_view.cc',
'browser/ui/views/omnibox/omnibox_popup_contents_view.h',
'browser/ui/views/omnibox/omnibox_result_view.cc',
......
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