OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_exit_bubble.h" | 5 #include "chrome/browser/ui/fullscreen_exit_bubble.h" |
6 | 6 |
7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
8 #include "ui/gfx/rect.h" | 8 #include "ui/gfx/rect.h" |
9 | 9 |
10 const double FullscreenExitBubble::kOpacity = 0.7; | 10 const double FullscreenExitBubble::kOpacity = 0.7; |
11 const int FullscreenExitBubble::kPaddingPx = 8; | 11 const int FullscreenExitBubble::kPaddingPx = 8; |
12 const int FullscreenExitBubble::kInitialDelayMs = 2300; | 12 const int FullscreenExitBubble::kInitialDelayMs = 2300; |
13 const int FullscreenExitBubble::kIdleTimeMs = 2300; | 13 const int FullscreenExitBubble::kIdleTimeMs = 2300; |
14 const int FullscreenExitBubble::kPositionCheckHz = 10; | 14 const int FullscreenExitBubble::kPositionCheckHz = 10; |
15 const int FullscreenExitBubble::kSlideInRegionHeightPx = 4; | 15 const int FullscreenExitBubble::kSlideInRegionHeightPx = 4; |
16 const int FullscreenExitBubble::kSlideInDurationMs = 350; | 16 const int FullscreenExitBubble::kSlideInDurationMs = 350; |
17 const int FullscreenExitBubble::kSlideOutDurationMs = 700; | 17 const int FullscreenExitBubble::kSlideOutDurationMs = 700; |
18 | 18 |
19 FullscreenExitBubble::FullscreenExitBubble( | 19 FullscreenExitBubble::FullscreenExitBubble( |
20 CommandUpdater::CommandUpdaterDelegate* delegate) | 20 CommandUpdater::CommandUpdaterDelegate* delegate) |
21 : delegate_(delegate) { | 21 : delegate_(delegate) { |
22 } | 22 } |
23 | 23 |
24 FullscreenExitBubble::~FullscreenExitBubble() { | 24 FullscreenExitBubble::~FullscreenExitBubble() { |
25 } | 25 } |
26 | 26 |
27 void FullscreenExitBubble::StartWatchingMouse() { | 27 void FullscreenExitBubble::StartWatchingMouse() { |
28 // Start the initial delay timer and begin watching the mouse. | 28 // Start the initial delay timer and begin watching the mouse. |
29 initial_delay_.Start(base::TimeDelta::FromMilliseconds(kInitialDelayMs), this, | 29 initial_delay_.Start(FROM_HERE, |
| 30 base::TimeDelta::FromMilliseconds(kInitialDelayMs), this, |
30 &FullscreenExitBubble::CheckMousePosition); | 31 &FullscreenExitBubble::CheckMousePosition); |
31 gfx::Point cursor_pos = GetCursorScreenPoint(); | 32 gfx::Point cursor_pos = GetCursorScreenPoint(); |
32 last_mouse_pos_ = cursor_pos; | 33 last_mouse_pos_ = cursor_pos; |
33 mouse_position_checker_.Start( | 34 mouse_position_checker_.Start(FROM_HERE, |
34 base::TimeDelta::FromMilliseconds(1000 / kPositionCheckHz), this, | 35 base::TimeDelta::FromMilliseconds(1000 / kPositionCheckHz), this, |
35 &FullscreenExitBubble::CheckMousePosition); | 36 &FullscreenExitBubble::CheckMousePosition); |
36 } | 37 } |
37 | 38 |
38 void FullscreenExitBubble::CheckMousePosition() { | 39 void FullscreenExitBubble::CheckMousePosition() { |
39 // Desired behavior: | 40 // Desired behavior: |
40 // | 41 // |
41 // +------------+-----------------------------+------------+ | 42 // +------------+-----------------------------+------------+ |
42 // | _ _ _ _ | Exit full screen mode (F11) | _ _ _ _ | Slide-in region | 43 // | _ _ _ _ | Exit full screen mode (F11) | _ _ _ _ | Slide-in region |
43 // | _ _ _ _ \_____________________________/ _ _ _ _ | Neutral region | 44 // | _ _ _ _ \_____________________________/ _ _ _ _ | Neutral region |
(...skipping 11 matching lines...) Expand all Loading... |
55 // * Otherwise, we do nothing, because the mouse is in the neutral region and | 56 // * Otherwise, we do nothing, because the mouse is in the neutral region and |
56 // either the popup is hidden or the mouse is not idle, so we don't want to | 57 // either the popup is hidden or the mouse is not idle, so we don't want to |
57 // change anything's state. | 58 // change anything's state. |
58 | 59 |
59 gfx::Point cursor_pos = GetCursorScreenPoint(); | 60 gfx::Point cursor_pos = GetCursorScreenPoint(); |
60 | 61 |
61 // Check to see whether the mouse is idle. | 62 // Check to see whether the mouse is idle. |
62 if (cursor_pos != last_mouse_pos_) { | 63 if (cursor_pos != last_mouse_pos_) { |
63 // The mouse moved; reset the idle timer. | 64 // The mouse moved; reset the idle timer. |
64 idle_timeout_.Stop(); // If the timer isn't running, this is a no-op. | 65 idle_timeout_.Stop(); // If the timer isn't running, this is a no-op. |
65 idle_timeout_.Start(base::TimeDelta::FromMilliseconds(kIdleTimeMs), this, | 66 idle_timeout_.Start(FROM_HERE, |
| 67 base::TimeDelta::FromMilliseconds(kIdleTimeMs), this, |
66 &FullscreenExitBubble::CheckMousePosition); | 68 &FullscreenExitBubble::CheckMousePosition); |
67 } | 69 } |
68 last_mouse_pos_ = cursor_pos; | 70 last_mouse_pos_ = cursor_pos; |
69 | 71 |
70 if (!IsWindowActive() || | 72 if (!IsWindowActive() || |
71 !WindowContainsPoint(cursor_pos) || | 73 !WindowContainsPoint(cursor_pos) || |
72 (cursor_pos.y() >= GetPopupRect(true).bottom()) || | 74 (cursor_pos.y() >= GetPopupRect(true).bottom()) || |
73 !idle_timeout_.IsRunning()) { | 75 !idle_timeout_.IsRunning()) { |
74 // The cursor is offscreen, in the slide-out region, or idle. | 76 // The cursor is offscreen, in the slide-out region, or idle. |
75 if (!initial_delay_.IsRunning()) { | 77 if (!initial_delay_.IsRunning()) { |
76 Hide(); | 78 Hide(); |
77 } | 79 } |
78 } else if ((cursor_pos.y() < kSlideInRegionHeightPx) || | 80 } else if ((cursor_pos.y() < kSlideInRegionHeightPx) || |
79 IsAnimating()) { | 81 IsAnimating()) { |
80 // The cursor is not idle, and either it's in the slide-in region or it's in | 82 // The cursor is not idle, and either it's in the slide-in region or it's in |
81 // the neutral region and we're sliding out. | 83 // the neutral region and we're sliding out. |
82 Show(); | 84 Show(); |
83 } | 85 } |
84 } | 86 } |
85 | 87 |
86 void FullscreenExitBubble::ToggleFullscreen() { | 88 void FullscreenExitBubble::ToggleFullscreen() { |
87 delegate_->ExecuteCommand(IDC_FULLSCREEN); | 89 delegate_->ExecuteCommand(IDC_FULLSCREEN); |
88 } | 90 } |
OLD | NEW |