OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/fullscreen/fullscreen_exit_bubble.h" | 5 #include "chrome/browser/ui/fullscreen/exclusive_access_bubble.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_commands.h" | 11 #include "chrome/browser/ui/browser_commands.h" |
12 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 12 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
13 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
14 #include "extensions/browser/extension_registry.h" | 14 #include "extensions/browser/extension_registry.h" |
15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
16 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
17 #include "ui/strings/grit/ui_strings.h" | 17 #include "ui/strings/grit/ui_strings.h" |
18 | 18 |
19 // NOTE(koz): Linux doesn't use the thick shadowed border, so we add padding | 19 // NOTE(koz): Linux doesn't use the thick shadowed border, so we add padding |
20 // here. | 20 // here. |
21 #if defined(OS_LINUX) | 21 #if defined(OS_LINUX) |
22 const int FullscreenExitBubble::kPaddingPx = 8; | 22 const int ExclusiveAccessBubble::kPaddingPx = 8; |
23 #else | 23 #else |
24 const int FullscreenExitBubble::kPaddingPx = 15; | 24 const int ExclusiveAccessBubble::kPaddingPx = 15; |
25 #endif | 25 #endif |
26 const int FullscreenExitBubble::kInitialDelayMs = 3800; | 26 const int ExclusiveAccessBubble::kInitialDelayMs = 3800; |
27 const int FullscreenExitBubble::kIdleTimeMs = 2300; | 27 const int ExclusiveAccessBubble::kIdleTimeMs = 2300; |
28 const int FullscreenExitBubble::kPositionCheckHz = 10; | 28 const int ExclusiveAccessBubble::kPositionCheckHz = 10; |
29 const int FullscreenExitBubble::kSlideInRegionHeightPx = 4; | 29 const int ExclusiveAccessBubble::kSlideInRegionHeightPx = 4; |
30 const int FullscreenExitBubble::kSlideInDurationMs = 350; | 30 const int ExclusiveAccessBubble::kSlideInDurationMs = 350; |
31 const int FullscreenExitBubble::kSlideOutDurationMs = 700; | 31 const int ExclusiveAccessBubble::kSlideOutDurationMs = 700; |
32 const int FullscreenExitBubble::kPopupTopPx = 15; | 32 const int ExclusiveAccessBubble::kPopupTopPx = 15; |
33 | 33 |
34 FullscreenExitBubble::FullscreenExitBubble(Browser* browser, | 34 ExclusiveAccessBubble::ExclusiveAccessBubble( |
35 const GURL& url, | 35 Browser* browser, |
36 FullscreenExitBubbleType bubble_type) | 36 const GURL& url, |
| 37 ExclusiveAccessBubbleType bubble_type) |
37 : browser_(browser), | 38 : browser_(browser), |
38 url_(url), | 39 url_(url), |
39 bubble_type_(bubble_type) { | 40 bubble_type_(bubble_type) { |
40 DCHECK_NE(FEB_TYPE_NONE, bubble_type_); | 41 DCHECK_NE(EAB_TYPE_NONE, bubble_type_); |
41 } | 42 } |
42 | 43 |
43 FullscreenExitBubble::~FullscreenExitBubble() { | 44 ExclusiveAccessBubble::~ExclusiveAccessBubble() { |
44 } | 45 } |
45 | 46 |
46 void FullscreenExitBubble::StartWatchingMouse() { | 47 void ExclusiveAccessBubble::StartWatchingMouse() { |
47 // Start the initial delay timer and begin watching the mouse. | 48 // Start the initial delay timer and begin watching the mouse. |
48 initial_delay_.Start(FROM_HERE, | 49 initial_delay_.Start(FROM_HERE, |
49 base::TimeDelta::FromMilliseconds(kInitialDelayMs), this, | 50 base::TimeDelta::FromMilliseconds(kInitialDelayMs), this, |
50 &FullscreenExitBubble::CheckMousePosition); | 51 &ExclusiveAccessBubble::CheckMousePosition); |
51 gfx::Point cursor_pos = GetCursorScreenPoint(); | 52 gfx::Point cursor_pos = GetCursorScreenPoint(); |
52 last_mouse_pos_ = cursor_pos; | 53 last_mouse_pos_ = cursor_pos; |
53 mouse_position_checker_.Start(FROM_HERE, | 54 mouse_position_checker_.Start(FROM_HERE, |
54 base::TimeDelta::FromMilliseconds(1000 / kPositionCheckHz), this, | 55 base::TimeDelta::FromMilliseconds(1000 / kPositionCheckHz), this, |
55 &FullscreenExitBubble::CheckMousePosition); | 56 &ExclusiveAccessBubble::CheckMousePosition); |
56 } | 57 } |
57 | 58 |
58 void FullscreenExitBubble::StopWatchingMouse() { | 59 void ExclusiveAccessBubble::StopWatchingMouse() { |
59 initial_delay_.Stop(); | 60 initial_delay_.Stop(); |
60 idle_timeout_.Stop(); | 61 idle_timeout_.Stop(); |
61 mouse_position_checker_.Stop(); | 62 mouse_position_checker_.Stop(); |
62 } | 63 } |
63 | 64 |
64 bool FullscreenExitBubble::IsWatchingMouse() const { | 65 bool ExclusiveAccessBubble::IsWatchingMouse() const { |
65 return mouse_position_checker_.IsRunning(); | 66 return mouse_position_checker_.IsRunning(); |
66 } | 67 } |
67 | 68 |
68 void FullscreenExitBubble::CheckMousePosition() { | 69 void ExclusiveAccessBubble::CheckMousePosition() { |
69 // Desired behavior: | 70 // Desired behavior: |
70 // | 71 // |
71 // +------------+-----------------------------+------------+ | 72 // +------------+-----------------------------+------------+ |
72 // | _ _ _ _ | Exit full screen mode (F11) | _ _ _ _ | Slide-in region | 73 // | _ _ _ _ | Exit full screen mode (F11) | _ _ _ _ | Slide-in region |
73 // | _ _ _ _ \_____________________________/ _ _ _ _ | Neutral region | 74 // | _ _ _ _ \_____________________________/ _ _ _ _ | Neutral region |
74 // | | Slide-out region | 75 // | | Slide-out region |
75 // : : | 76 // : : |
76 // | 77 // |
77 // * If app is not active, we hide the popup. | 78 // * 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 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 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 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 // * 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 // currently sliding out, we show it again. This facilitates users |
83 // correcting us if they try to mouse horizontally towards the popup and | 84 // correcting us if they try to mouse horizontally towards the popup and |
84 // unintentionally drop too low. | 85 // unintentionally drop too low. |
85 // * Otherwise, we do nothing, because the mouse is in the neutral region and | 86 // * 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 // either the popup is hidden or the mouse is not idle, so we don't want to |
87 // change anything's state. | 88 // change anything's state. |
88 | 89 |
89 gfx::Point cursor_pos = GetCursorScreenPoint(); | 90 gfx::Point cursor_pos = GetCursorScreenPoint(); |
90 | 91 |
91 // Check to see whether the mouse is idle. | 92 // Check to see whether the mouse is idle. |
92 if (cursor_pos != last_mouse_pos_) { | 93 if (cursor_pos != last_mouse_pos_) { |
93 // The mouse moved; reset the idle timer. | 94 // 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_.Stop(); // If the timer isn't running, this is a no-op. |
95 idle_timeout_.Start(FROM_HERE, | 96 idle_timeout_.Start(FROM_HERE, |
96 base::TimeDelta::FromMilliseconds(kIdleTimeMs), this, | 97 base::TimeDelta::FromMilliseconds(kIdleTimeMs), this, |
97 &FullscreenExitBubble::CheckMousePosition); | 98 &ExclusiveAccessBubble::CheckMousePosition); |
98 } | 99 } |
99 last_mouse_pos_ = cursor_pos; | 100 last_mouse_pos_ = cursor_pos; |
100 | 101 |
101 if (!IsWindowActive() || | 102 if (!IsWindowActive() || |
102 !WindowContainsPoint(cursor_pos) || | 103 !WindowContainsPoint(cursor_pos) || |
103 (cursor_pos.y() >= GetPopupRect(true).bottom()) || | 104 (cursor_pos.y() >= GetPopupRect(true).bottom()) || |
104 !idle_timeout_.IsRunning()) { | 105 !idle_timeout_.IsRunning()) { |
105 // The cursor is offscreen, in the slide-out region, or idle. | 106 // The cursor is offscreen, in the slide-out region, or idle. |
106 if (!initial_delay_.IsRunning()) { | 107 if (!initial_delay_.IsRunning()) { |
107 Hide(); | 108 Hide(); |
108 } | 109 } |
109 } else if (cursor_pos.y() < kSlideInRegionHeightPx && | 110 } else if (cursor_pos.y() < kSlideInRegionHeightPx && |
110 CanMouseTriggerSlideIn()) { | 111 CanMouseTriggerSlideIn()) { |
111 Show(); | 112 Show(); |
112 } else if (IsAnimating()) { | 113 } else if (IsAnimating()) { |
113 // The cursor is not idle and either it's in the slide-in region or it's in | 114 // 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. | 115 // the neutral region and we're sliding in or out. |
115 Show(); | 116 Show(); |
116 } | 117 } |
117 } | 118 } |
118 | 119 |
119 void FullscreenExitBubble::ToggleFullscreen() { | 120 void ExclusiveAccessBubble::ToggleFullscreen() { |
120 browser_->fullscreen_controller()-> | 121 browser_->fullscreen_controller()-> |
121 ExitTabOrBrowserFullscreenToPreviousState(); | 122 ExitTabOrBrowserFullscreenToPreviousState(); |
122 } | 123 } |
123 | 124 |
124 void FullscreenExitBubble::Accept() { | 125 void ExclusiveAccessBubble::Accept() { |
125 browser_->fullscreen_controller()->OnAcceptFullscreenPermission(); | 126 browser_->fullscreen_controller()->OnAcceptFullscreenPermission(); |
126 } | 127 } |
127 | 128 |
128 void FullscreenExitBubble::Cancel() { | 129 void ExclusiveAccessBubble::Cancel() { |
129 browser_->fullscreen_controller()->OnDenyFullscreenPermission(); | 130 browser_->fullscreen_controller()->OnDenyFullscreenPermission(); |
130 } | 131 } |
131 | 132 |
132 base::string16 FullscreenExitBubble::GetCurrentMessageText() const { | 133 base::string16 ExclusiveAccessBubble::GetCurrentMessageText() const { |
133 return fullscreen_bubble::GetLabelTextForType( | 134 return exclusive_access_bubble::GetLabelTextForType( |
134 bubble_type_, url_, | 135 bubble_type_, url_, |
135 extensions::ExtensionRegistry::Get(browser_->profile())); | 136 extensions::ExtensionRegistry::Get(browser_->profile())); |
136 } | 137 } |
137 | 138 |
138 base::string16 FullscreenExitBubble::GetCurrentDenyButtonText() const { | 139 base::string16 ExclusiveAccessBubble::GetCurrentDenyButtonText() const { |
139 return fullscreen_bubble::GetDenyButtonTextForType(bubble_type_); | 140 return exclusive_access_bubble::GetDenyButtonTextForType(bubble_type_); |
140 } | 141 } |
141 | 142 |
142 base::string16 FullscreenExitBubble::GetAllowButtonText() const { | 143 base::string16 ExclusiveAccessBubble::GetAllowButtonText() const { |
143 return l10n_util::GetStringUTF16(IDS_FULLSCREEN_ALLOW); | 144 return l10n_util::GetStringUTF16(IDS_FULLSCREEN_ALLOW); |
144 } | 145 } |
145 | 146 |
146 base::string16 FullscreenExitBubble::GetInstructionText() const { | 147 base::string16 ExclusiveAccessBubble::GetInstructionText() const { |
147 return l10n_util::GetStringFUTF16(IDS_FULLSCREEN_PRESS_ESC_TO_EXIT, | 148 return l10n_util::GetStringFUTF16(IDS_FULLSCREEN_PRESS_ESC_TO_EXIT, |
148 l10n_util::GetStringUTF16(IDS_APP_ESC_KEY)); | 149 l10n_util::GetStringUTF16(IDS_APP_ESC_KEY)); |
149 } | 150 } |
OLD | NEW |