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"
14 class ExclusiveAccessManager
;
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.
23 class ExclusiveAccessBubble
: public gfx::AnimationDelegate
{
25 explicit ExclusiveAccessBubble(ExclusiveAccessManager
* manager
,
27 ExclusiveAccessBubbleType bubble_type
);
28 ~ExclusiveAccessBubble() override
;
31 static const int kPaddingPx
; // Amount of padding around the link
32 static const int kInitialDelayMs
; // Initial time bubble remains onscreen
33 static const int kIdleTimeMs
; // Time before mouse idle triggers hide
34 static const int kPositionCheckHz
; // How fast to check the mouse position
35 static const int kSlideInRegionHeightPx
;
36 // Height of region triggering
38 static const int kPopupTopPx
; // Space between the popup and the top
40 static const int kSlideInDurationMs
; // Duration of slide-in animation
41 static const int kSlideOutDurationMs
; // Duration of slide-out animation
43 // Returns the current desirable rect for the popup window. If
44 // |ignore_animation_state| is true this returns the rect assuming the popup
46 virtual gfx::Rect
GetPopupRect(bool ignore_animation_state
) const = 0;
47 virtual gfx::Point
GetCursorScreenPoint() = 0;
48 virtual bool WindowContainsPoint(gfx::Point pos
) = 0;
50 // Returns true if the window is active.
51 virtual bool IsWindowActive() = 0;
53 // Hides the bubble. This is a separate function so it can be called by a
55 virtual void Hide() = 0;
58 virtual void Show() = 0;
60 virtual bool IsAnimating() = 0;
62 // True if the mouse position can trigger sliding in the exit fullscreen
63 // bubble when the bubble is hidden.
64 virtual bool CanMouseTriggerSlideIn() const = 0;
66 void StartWatchingMouse();
67 void StopWatchingMouse();
68 bool IsWatchingMouse() const;
70 // Called repeatedly to get the current mouse position and animate the bubble
71 // on or off the screen as appropriate.
72 void CheckMousePosition();
74 void ExitExclusiveAccess();
75 // Accepts the request. Can cause FullscreenExitBubble to be deleted.
77 // Denys the request. Can cause FullscreenExitBubble to be deleted.
80 // The following strings may change according to the content type and URL.
81 base::string16
GetCurrentMessageText() const;
82 base::string16
GetCurrentDenyButtonText() const;
83 base::string16
GetCurrentAllowButtonText() const;
85 // The following strings never change.
86 base::string16
GetInstructionText() const;
88 // The Manager associated with this bubble.
89 ExclusiveAccessManager
* const manager_
;
91 // The host the bubble is for, can be empty.
94 // The type of the bubble; controls e.g. which buttons to show.
95 ExclusiveAccessBubbleType bubble_type_
;
98 // Timer to delay before allowing the bubble to hide after it's initially
100 base::OneShotTimer
<ExclusiveAccessBubble
> initial_delay_
;
102 // Timer to see how long the mouse has been idle.
103 base::OneShotTimer
<ExclusiveAccessBubble
> idle_timeout_
;
105 // Timer to poll the current mouse position. We can't just listen for mouse
106 // events without putting a non-empty HWND onscreen (or hooking Windows, which
107 // has other problems), so instead we run a low-frequency poller to see if the
108 // user has moved in or out of our show/hide regions.
109 base::RepeatingTimer
<ExclusiveAccessBubble
> mouse_position_checker_
;
111 // The most recently seen mouse position, in screen coordinates. Used to see
112 // if the mouse has moved since our last check.
113 gfx::Point last_mouse_pos_
;
115 DISALLOW_COPY_AND_ASSIGN(ExclusiveAccessBubble
);
118 #endif // CHROME_BROWSER_UI_EXCLUSIVE_ACCESS_EXCLUSIVE_ACCESS_BUBBLE_H_