Add ability to gather metrics to BubbleManager.
[chromium-blink-merge.git] / chrome / browser / ui / exclusive_access / exclusive_access_bubble.h
blob63bbc48ae7d6bd10f105067f83742384edfc9149
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.
5 #ifndef CHROME_BROWSER_UI_EXCLUSIVE_ACCESS_EXCLUSIVE_ACCESS_BUBBLE_H_
6 #define CHROME_BROWSER_UI_EXCLUSIVE_ACCESS_EXCLUSIVE_ACCESS_BUBBLE_H_
8 #include "base/timer/timer.h"
9 #include "chrome/browser/ui/exclusive_access/exclusive_access_bubble_type.h"
10 #include "ui/gfx/animation/animation_delegate.h"
11 #include "ui/gfx/geometry/point.h"
12 #include "url/gurl.h"
14 class ExclusiveAccessManager;
16 namespace gfx {
17 class Rect;
20 // Bubble that informs the user when an exclusive access state is in effect and
21 // as to how to exit out of the state. Currently there are two exclusive access
22 // state, namely fullscreen and mouse lock.
24 // Notification display design note: if the #simplified-fullscreen-ui flag is
25 // enabled, the bubble has the following behaviour:
26 // - Upon taking exclusive access, wait kDebounceNotificationsTimeMs, then for
27 // user input, before displaying the bubble.
28 // - The bubble is shown for kIdleTimeMs, then hides.
29 // - After a bubble has been shown, notifications are suppressed for
30 // kSnoozeNotificationsTimeMs, to avoid bothering the user. After this time
31 // has elapsed, the next user input re-displays the bubble.
32 class ExclusiveAccessBubble : public gfx::AnimationDelegate {
33 public:
34 explicit ExclusiveAccessBubble(ExclusiveAccessManager* manager,
35 const GURL& url,
36 ExclusiveAccessBubbleType bubble_type);
37 ~ExclusiveAccessBubble() override;
39 protected:
40 static const int kPaddingPx; // Amount of padding around the link
41 static const int kInitialDelayMs; // Initial time bubble remains onscreen
42 static const int kIdleTimeMs; // Time before mouse idle triggers hide
43 // See notification display design note above.
44 static const int kDebounceNotificationsTimeMs;
45 static const int kSnoozeNotificationsTimeMs;
46 static const int kPositionCheckHz; // How fast to check the mouse position
47 static const int kSlideInRegionHeightPx;
48 // Height of region triggering
49 // slide-in
50 static const int kPopupTopPx; // Space between the popup and the top
51 // of the screen.
52 static const int kSlideInDurationMs; // Duration of slide-in animation
53 static const int kSlideOutDurationMs; // Duration of slide-out animation
55 // Returns the current desirable rect for the popup window. If
56 // |ignore_animation_state| is true this returns the rect assuming the popup
57 // is fully onscreen.
58 virtual gfx::Rect GetPopupRect(bool ignore_animation_state) const = 0;
59 virtual gfx::Point GetCursorScreenPoint() = 0;
60 virtual bool WindowContainsPoint(gfx::Point pos) = 0;
62 // Returns true if the window is active.
63 virtual bool IsWindowActive() = 0;
65 // Hides the bubble. This is a separate function so it can be called by a
66 // timer.
67 virtual void Hide() = 0;
69 // Shows the bubble.
70 virtual void Show() = 0;
72 virtual bool IsAnimating() = 0;
74 // True if the mouse position can trigger sliding in the exit fullscreen
75 // bubble when the bubble is hidden.
76 virtual bool CanMouseTriggerSlideIn() const = 0;
78 void StartWatchingMouse();
79 void StopWatchingMouse();
80 bool IsWatchingMouse() const;
82 // Called repeatedly to get the current mouse position and animate the bubble
83 // on or off the screen as appropriate.
84 void CheckMousePosition();
86 void ExitExclusiveAccess();
87 // Accepts the request. Can cause FullscreenExitBubble to be deleted.
88 void Accept();
89 // Denys the request. Can cause FullscreenExitBubble to be deleted.
90 void Cancel();
92 // The following strings may change according to the content type and URL.
93 base::string16 GetCurrentMessageText() const;
94 base::string16 GetCurrentDenyButtonText() const;
95 base::string16 GetCurrentAllowButtonText() const;
97 // The following strings never change.
98 base::string16 GetInstructionText() const;
100 // The Manager associated with this bubble.
101 ExclusiveAccessManager* const manager_;
103 // The host the bubble is for, can be empty.
104 GURL url_;
106 // The type of the bubble; controls e.g. which buttons to show.
107 ExclusiveAccessBubbleType bubble_type_;
109 private:
110 // When this timer is active, prevent the bubble from hiding. This ensures it
111 // will be displayed for a minimum amount of time (which can be extended by
112 // the user moving the mouse to the top of the screen and holding it there).
113 base::OneShotTimer<ExclusiveAccessBubble> hide_timeout_;
115 // Timer to see how long the mouse has been idle.
116 base::OneShotTimer<ExclusiveAccessBubble> idle_timeout_;
118 // When this timer has elapsed, on the next mouse input, we will notify the
119 // user about any currently active exclusive access. This is used to enact
120 // both the initial debounce period, and the snooze period before re-notifying
121 // the user (see notification display design note above).
122 base::OneShotTimer<ExclusiveAccessBubble> suppress_notify_timeout_;
124 // Timer to poll the current mouse position. We can't just listen for mouse
125 // events without putting a non-empty HWND onscreen (or hooking Windows, which
126 // has other problems), so instead we run a low-frequency poller to see if the
127 // user has moved in or out of our show/hide regions.
128 base::RepeatingTimer<ExclusiveAccessBubble> mouse_position_checker_;
130 // The most recently seen mouse position, in screen coordinates. Used to see
131 // if the mouse has moved since our last check.
132 gfx::Point last_mouse_pos_;
134 DISALLOW_COPY_AND_ASSIGN(ExclusiveAccessBubble);
137 #endif // CHROME_BROWSER_UI_EXCLUSIVE_ACCESS_EXCLUSIVE_ACCESS_BUBBLE_H_