Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / exclusive_access / exclusive_access_bubble.cc
blobcdb483bbcaef74ef2e52e8f29b128cabdfe96c30
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/exclusive_access/exclusive_access_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/exclusive_access/exclusive_access_context.h"
11 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
12 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "extensions/browser/extension_registry.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/gfx/geometry/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
20 // here.
21 #if defined(OS_LINUX)
22 const int ExclusiveAccessBubble::kPaddingPx = 8;
23 #else
24 const int ExclusiveAccessBubble::kPaddingPx = 15;
25 #endif
26 const int ExclusiveAccessBubble::kInitialDelayMs = 3800;
27 const int ExclusiveAccessBubble::kIdleTimeMs = 2300;
28 const int ExclusiveAccessBubble::kDebounceNotificationsTimeMs = 500;
29 const int ExclusiveAccessBubble::kSnoozeNotificationsTimeMs = 3600000; // 1hr.
30 const int ExclusiveAccessBubble::kPositionCheckHz = 10;
31 const int ExclusiveAccessBubble::kSlideInRegionHeightPx = 4;
32 const int ExclusiveAccessBubble::kSlideInDurationMs = 350;
33 const int ExclusiveAccessBubble::kSlideOutDurationMs = 700;
34 const int ExclusiveAccessBubble::kPopupTopPx = 15;
36 ExclusiveAccessBubble::ExclusiveAccessBubble(
37 ExclusiveAccessManager* manager,
38 const GURL& url,
39 ExclusiveAccessBubbleType bubble_type)
40 : manager_(manager), url_(url), bubble_type_(bubble_type) {
41 DCHECK_NE(EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE, bubble_type_);
43 // Wait for a short time to let the user stop moving the mouse. After this
44 // time elapses, we will notify the user upon the next mouse input.
45 if (ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled()) {
46 suppress_notify_timeout_.Start(
47 FROM_HERE,
48 base::TimeDelta::FromMilliseconds(kDebounceNotificationsTimeMs), this,
49 &ExclusiveAccessBubble::CheckMousePosition);
53 ExclusiveAccessBubble::~ExclusiveAccessBubble() {
56 void ExclusiveAccessBubble::StartWatchingMouse() {
57 // Start the initial delay timer and begin watching the mouse.
58 if (!ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled()) {
59 hide_timeout_.Start(FROM_HERE,
60 base::TimeDelta::FromMilliseconds(kInitialDelayMs),
61 this, &ExclusiveAccessBubble::CheckMousePosition);
63 gfx::Point cursor_pos = GetCursorScreenPoint();
64 last_mouse_pos_ = cursor_pos;
65 mouse_position_checker_.Start(
66 FROM_HERE, base::TimeDelta::FromMilliseconds(1000 / kPositionCheckHz),
67 this, &ExclusiveAccessBubble::CheckMousePosition);
70 void ExclusiveAccessBubble::StopWatchingMouse() {
71 hide_timeout_.Stop();
72 idle_timeout_.Stop();
73 mouse_position_checker_.Stop();
76 bool ExclusiveAccessBubble::IsWatchingMouse() const {
77 return mouse_position_checker_.IsRunning();
80 void ExclusiveAccessBubble::CheckMousePosition() {
81 // Desired behavior:
83 // +------------+-----------------------------+------------+
84 // | _ _ _ _ | Exit full screen mode (F11) | _ _ _ _ | Slide-in region
85 // | _ _ _ _ \_____________________________/ _ _ _ _ | Neutral region
86 // | | Slide-out region
87 // : :
89 // * If app is not active, we hide the popup.
90 // * If the mouse is offscreen or in the slide-out region, we hide the popup.
91 // * If the mouse goes idle, we hide the popup.
92 // * If the mouse is in the slide-in-region and not idle, we show the popup.
93 // * If the mouse is in the neutral region and not idle, and the popup is
94 // currently sliding out, we show it again. This facilitates users
95 // correcting us if they try to mouse horizontally towards the popup and
96 // unintentionally drop too low.
97 // * Otherwise, we do nothing, because the mouse is in the neutral region and
98 // either the popup is hidden or the mouse is not idle, so we don't want to
99 // change anything's state.
101 gfx::Point cursor_pos = GetCursorScreenPoint();
103 // Check to see whether the mouse is idle.
104 if (cursor_pos != last_mouse_pos_) {
105 // The mouse moved; reset the idle timer.
106 idle_timeout_.Stop(); // If the timer isn't running, this is a no-op.
107 idle_timeout_.Start(FROM_HERE,
108 base::TimeDelta::FromMilliseconds(kIdleTimeMs), this,
109 &ExclusiveAccessBubble::CheckMousePosition);
111 if (ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled()) {
112 // If the notification suppression timer has elapsed, show the
113 // notification regardless of where the mouse is on the screen.
114 if (!suppress_notify_timeout_.IsRunning()) {
115 Show();
116 // Do not allow the notification to hide for a few seconds.
117 hide_timeout_.Start(FROM_HERE,
118 base::TimeDelta::FromMilliseconds(kIdleTimeMs),
119 this, &ExclusiveAccessBubble::CheckMousePosition);
120 // Do not show the notification again until a long time has elapsed.
121 suppress_notify_timeout_.Start(
122 FROM_HERE,
123 base::TimeDelta::FromMilliseconds(kSnoozeNotificationsTimeMs), this,
124 &ExclusiveAccessBubble::CheckMousePosition);
125 return;
126 } else {
127 // The timer has not elapsed, but the user moved the mouse. Reset the
128 // timer. (We only want to re-show the message after a period of
129 // inactivity.)
130 suppress_notify_timeout_.Reset();
134 last_mouse_pos_ = cursor_pos;
136 if (!IsWindowActive() || !WindowContainsPoint(cursor_pos) ||
137 (cursor_pos.y() >= GetPopupRect(true).bottom()) ||
138 !idle_timeout_.IsRunning()) {
139 // The cursor is offscreen, in the slide-out region, or idle.
140 if (!hide_timeout_.IsRunning()) {
141 Hide();
143 } else if (cursor_pos.y() < kSlideInRegionHeightPx &&
144 CanMouseTriggerSlideIn()) {
145 Show();
146 } else if (IsAnimating()) {
147 // The cursor is not idle and either it's in the slide-in region or it's in
148 // the neutral region and we're sliding in or out.
149 Show();
153 void ExclusiveAccessBubble::ExitExclusiveAccess() {
154 manager_->ExitExclusiveAccess();
157 void ExclusiveAccessBubble::Accept() {
158 manager_->OnAcceptExclusiveAccessPermission();
161 void ExclusiveAccessBubble::Cancel() {
162 manager_->OnDenyExclusiveAccessPermission();
165 base::string16 ExclusiveAccessBubble::GetCurrentMessageText() const {
166 return exclusive_access_bubble::GetLabelTextForType(
167 bubble_type_, url_,
168 extensions::ExtensionRegistry::Get(manager_->context()->GetProfile()));
171 base::string16 ExclusiveAccessBubble::GetCurrentDenyButtonText() const {
172 return exclusive_access_bubble::GetDenyButtonTextForType(bubble_type_);
175 base::string16 ExclusiveAccessBubble::GetCurrentAllowButtonText() const {
176 return exclusive_access_bubble::GetAllowButtonTextForType(bubble_type_, url_);
179 base::string16 ExclusiveAccessBubble::GetInstructionText() const {
180 return l10n_util::GetStringFUTF16(IDS_FULLSCREEN_PRESS_ESC_TO_EXIT,
181 l10n_util::GetStringUTF16(IDS_APP_ESC_KEY));