1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_UI_VIEWS_EXCLUSIVE_ACCESS_BUBBLE_VIEWS_H_
6 #define CHROME_BROWSER_UI_VIEWS_EXCLUSIVE_ACCESS_BUBBLE_VIEWS_H_
7 
8 #include <memory>
9 
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "base/scoped_observer.h"
13 #include "chrome/browser/ui/exclusive_access/exclusive_access_bubble.h"
14 #include "chrome/browser/ui/exclusive_access/exclusive_access_bubble_hide_callback.h"
15 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
16 #include "chrome/browser/ui/exclusive_access/fullscreen_observer.h"
17 #include "ui/views/widget/widget_observer.h"
18 
19 class ExclusiveAccessBubbleViewsContext;
20 class GURL;
21 namespace gfx {
22 class SlideAnimation;
23 }
24 namespace views {
25 class View;
26 class Widget;
27 }
28 
29 class SubtleNotificationView;
30 
31 // ExclusiveAccessBubbleViews is responsible for showing a bubble atop the
32 // screen in fullscreen/mouse lock mode, telling users how to exit and providing
33 // a click target. The bubble auto-hides, and re-shows when the user moves to
34 // the screen top.
35 class ExclusiveAccessBubbleViews : public ExclusiveAccessBubble,
36                                    public FullscreenObserver,
37                                    public views::WidgetObserver {
38  public:
39   ExclusiveAccessBubbleViews(
40       ExclusiveAccessBubbleViewsContext* context,
41       const GURL& url,
42       ExclusiveAccessBubbleType bubble_type,
43       ExclusiveAccessBubbleHideCallback bubble_first_hide_callback);
44   ~ExclusiveAccessBubbleViews() override;
45 
46   // |force_update| indicates the caller wishes to show the bubble contents
47   // regardless of whether the contents have changed.
48   void UpdateContent(
49       const GURL& url,
50       ExclusiveAccessBubbleType bubble_type,
51       ExclusiveAccessBubbleHideCallback bubble_first_hide_callback,
52       bool force_update);
53 
54   // Repositions |popup_| if it is visible.
55   void RepositionIfVisible();
56 
57   // If popup is visible, hides |popup_| before the bubble automatically hides
58   // itself.
59   void HideImmediately();
60 
61   // Returns true if the popup is being shown (and not fully shown).
62   bool IsShowing() const;
63 
64   views::View* GetView();
65 
animation_for_test()66   gfx::SlideAnimation* animation_for_test() { return animation_.get(); }
67 
68  private:
69   // Starts or stops polling the mouse location based on |popup_| and
70   // |bubble_type_|.
71   void UpdateMouseWatcher();
72 
73   // Updates |popup|'s bounds given |animation_| and |animated_attribute_|.
74   void UpdateBounds();
75 
76   void UpdateViewContent(ExclusiveAccessBubbleType bubble_type);
77 
78   // Returns the root view containing |browser_view_|.
79   views::View* GetBrowserRootView() const;
80 
81   // ExclusiveAccessBubble:
82   void AnimationProgressed(const gfx::Animation* animation) override;
83   void AnimationEnded(const gfx::Animation* animation) override;
84   gfx::Rect GetPopupRect(bool ignore_animation_state) const override;
85   gfx::Point GetCursorScreenPoint() override;
86   bool WindowContainsPoint(gfx::Point pos) override;
87   bool IsWindowActive() override;
88   void Hide() override;
89   void Show() override;
90   bool IsAnimating() override;
91   bool CanTriggerOnMouse() const override;
92 
93   // FullscreenObserver:
94   void OnFullscreenStateChanged() override;
95 
96   // views::WidgetObserver:
97   void OnWidgetDestroyed(views::Widget* widget) override;
98   void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override;
99 
100   void RunHideCallbackIfNeeded(ExclusiveAccessBubbleHideReason reason);
101 
102   ExclusiveAccessBubbleViewsContext* const bubble_view_context_;
103 
104   views::Widget* popup_;
105 
106   // Classic mode: Bubble may show & hide multiple times. The callback only runs
107   // for the first hide.
108   // Simplified mode: Bubble only hides once.
109   ExclusiveAccessBubbleHideCallback bubble_first_hide_callback_;
110 
111   // Animation controlling showing/hiding of the exit bubble.
112   std::unique_ptr<gfx::SlideAnimation> animation_;
113 
114   // The contents of the popup.
115   SubtleNotificationView* view_;
116   base::string16 browser_fullscreen_exit_accelerator_;
117 
118   ScopedObserver<FullscreenController, FullscreenObserver> fullscreen_observer_{
119       this};
120 
121   DISALLOW_COPY_AND_ASSIGN(ExclusiveAccessBubbleViews);
122 };
123 
124 #endif  // CHROME_BROWSER_UI_VIEWS_EXCLUSIVE_ACCESS_BUBBLE_VIEWS_H_
125