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