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 #include "chrome/browser/ui/fullscreen/fullscreen_exit_bubble.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_commands.h"
12 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "extensions/browser/extension_system.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/gfx/rect.h"
17 #include "ui/strings/grit/ui_strings.h"
19 // NOTE(koz): Linux doesn't use the thick shadowed border, so we add padding
22 const int FullscreenExitBubble::kPaddingPx
= 8;
24 const int FullscreenExitBubble::kPaddingPx
= 15;
26 const int FullscreenExitBubble::kInitialDelayMs
= 3800;
27 const int FullscreenExitBubble::kIdleTimeMs
= 2300;
28 const int FullscreenExitBubble::kPositionCheckHz
= 10;
29 const int FullscreenExitBubble::kSlideInRegionHeightPx
= 4;
30 const int FullscreenExitBubble::kSlideInDurationMs
= 350;
31 const int FullscreenExitBubble::kSlideOutDurationMs
= 700;
32 const int FullscreenExitBubble::kPopupTopPx
= 15;
34 FullscreenExitBubble::FullscreenExitBubble(Browser
* browser
,
36 FullscreenExitBubbleType bubble_type
)
39 bubble_type_(bubble_type
) {
40 DCHECK_NE(FEB_TYPE_NONE
, bubble_type_
);
43 FullscreenExitBubble::~FullscreenExitBubble() {
46 void FullscreenExitBubble::StartWatchingMouse() {
47 // Start the initial delay timer and begin watching the mouse.
48 initial_delay_
.Start(FROM_HERE
,
49 base::TimeDelta::FromMilliseconds(kInitialDelayMs
), this,
50 &FullscreenExitBubble::CheckMousePosition
);
51 gfx::Point cursor_pos
= GetCursorScreenPoint();
52 last_mouse_pos_
= cursor_pos
;
53 mouse_position_checker_
.Start(FROM_HERE
,
54 base::TimeDelta::FromMilliseconds(1000 / kPositionCheckHz
), this,
55 &FullscreenExitBubble::CheckMousePosition
);
58 void FullscreenExitBubble::StopWatchingMouse() {
59 initial_delay_
.Stop();
61 mouse_position_checker_
.Stop();
64 bool FullscreenExitBubble::IsWatchingMouse() const {
65 return mouse_position_checker_
.IsRunning();
68 void FullscreenExitBubble::CheckMousePosition() {
71 // +------------+-----------------------------+------------+
72 // | _ _ _ _ | Exit full screen mode (F11) | _ _ _ _ | Slide-in region
73 // | _ _ _ _ \_____________________________/ _ _ _ _ | Neutral region
74 // | | Slide-out region
77 // * If app is not active, we hide the popup.
78 // * If the mouse is offscreen or in the slide-out region, we hide the popup.
79 // * If the mouse goes idle, we hide the popup.
80 // * If the mouse is in the slide-in-region and not idle, we show the popup.
81 // * If the mouse is in the neutral region and not idle, and the popup is
82 // currently sliding out, we show it again. This facilitates users
83 // correcting us if they try to mouse horizontally towards the popup and
84 // unintentionally drop too low.
85 // * Otherwise, we do nothing, because the mouse is in the neutral region and
86 // either the popup is hidden or the mouse is not idle, so we don't want to
87 // change anything's state.
89 gfx::Point cursor_pos
= GetCursorScreenPoint();
91 // Check to see whether the mouse is idle.
92 if (cursor_pos
!= last_mouse_pos_
) {
93 // The mouse moved; reset the idle timer.
94 idle_timeout_
.Stop(); // If the timer isn't running, this is a no-op.
95 idle_timeout_
.Start(FROM_HERE
,
96 base::TimeDelta::FromMilliseconds(kIdleTimeMs
), this,
97 &FullscreenExitBubble::CheckMousePosition
);
99 last_mouse_pos_
= cursor_pos
;
101 if (!IsWindowActive() ||
102 !WindowContainsPoint(cursor_pos
) ||
103 (cursor_pos
.y() >= GetPopupRect(true).bottom()) ||
104 !idle_timeout_
.IsRunning()) {
105 // The cursor is offscreen, in the slide-out region, or idle.
106 if (!initial_delay_
.IsRunning()) {
109 } else if (cursor_pos
.y() < kSlideInRegionHeightPx
&&
110 CanMouseTriggerSlideIn()) {
112 } else if (IsAnimating()) {
113 // The cursor is not idle and either it's in the slide-in region or it's in
114 // the neutral region and we're sliding in or out.
119 void FullscreenExitBubble::ToggleFullscreen() {
120 browser_
->fullscreen_controller()->
121 ExitTabOrBrowserFullscreenToPreviousState();
124 void FullscreenExitBubble::Accept() {
125 browser_
->fullscreen_controller()->OnAcceptFullscreenPermission();
128 void FullscreenExitBubble::Cancel() {
129 browser_
->fullscreen_controller()->OnDenyFullscreenPermission();
132 base::string16
FullscreenExitBubble::GetCurrentMessageText() const {
133 return fullscreen_bubble::GetLabelTextForType(
135 extensions::ExtensionSystem::Get(
136 browser_
->profile())->extension_service());
139 base::string16
FullscreenExitBubble::GetCurrentDenyButtonText() const {
140 return fullscreen_bubble::GetDenyButtonTextForType(bubble_type_
);
143 base::string16
FullscreenExitBubble::GetAllowButtonText() const {
144 return l10n_util::GetStringUTF16(IDS_FULLSCREEN_ALLOW
);
147 base::string16
FullscreenExitBubble::GetInstructionText() const {
148 return l10n_util::GetStringFUTF16(IDS_FULLSCREEN_PRESS_ESC_TO_EXIT
,
149 l10n_util::GetStringUTF16(IDS_APP_ESC_KEY
));