blob: 008df33b4c743c81c28d43cbed7688da7e3d0992 [file] [log] [blame]
// Copyright 2017 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_CLOSE_BUBBLE_ON_TAB_ACTIVATION_HELPER_H_
#define CHROME_BROWSER_UI_VIEWS_CLOSE_BUBBLE_ON_TAB_ACTIVATION_HELPER_H_
#include "base/scoped_observer.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
class Browser;
namespace views {
class BubbleDialogDelegateView;
}
// Helper class that closes the bubble view every time the active tab changes.
// That is required as on macOS, the user may use the keyboard shortcuts to
// add, close or change the active tab.
class CloseBubbleOnTabActivationHelper : public TabStripModelObserver {
public:
// It is the expectation of this class that |bubble| and |browser| should
// outlive it. The recommended usage is for |bubble| to own |this|.
CloseBubbleOnTabActivationHelper(
views::BubbleDialogDelegateView* owner_bubble,
Browser* browser);
~CloseBubbleOnTabActivationHelper() override;
// TabStripModelObserver:
void ActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
int reason) override;
private:
views::BubbleDialogDelegateView* owner_bubble_; // weak, owns me.
ScopedObserver<TabStripModel, CloseBubbleOnTabActivationHelper>
tab_strip_observer_;
DISALLOW_COPY_AND_ASSIGN(CloseBubbleOnTabActivationHelper);
};
#endif // CHROME_BROWSER_UI_VIEWS_CLOSE_BUBBLE_ON_TAB_ACTIVATION_HELPER_H_