Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: ash/accelerators/exit_warning_handler.cc

Issue 2168483006: Converts exit_warning_handler to use ash common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ash/accelerators/exit_warning_handler.h" 5 #include "ash/accelerators/exit_warning_handler.h"
msw 2016/07/20 23:35:25 optional nit: move to ash/common/accelerators?
6 6
7 #include "ash/common/shell_delegate.h" 7 #include "ash/common/shell_delegate.h"
8 #include "ash/common/shell_window_ids.h" 8 #include "ash/common/shell_window_ids.h"
9 #include "ash/common/wm_root_window_controller.h"
9 #include "ash/common/wm_shell.h" 10 #include "ash/common/wm_shell.h"
10 #include "ash/shell.h" 11 #include "ash/common/wm_window.h"
11 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
12 #include "base/time/time.h" 13 #include "base/time/time.h"
13 #include "base/timer/timer.h" 14 #include "base/timer/timer.h"
14 #include "grit/ash_strings.h" 15 #include "grit/ash_strings.h"
15 #include "ui/accessibility/ax_view_state.h" 16 #include "ui/accessibility/ax_view_state.h"
16 #include "ui/aura/window.h"
17 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
20 #include "ui/gfx/font_list.h" 20 #include "ui/gfx/font_list.h"
21 #include "ui/gfx/text_utils.h" 21 #include "ui/gfx/text_utils.h"
22 #include "ui/views/controls/label.h" 22 #include "ui/views/controls/label.h"
23 #include "ui/views/layout/fill_layout.h" 23 #include "ui/views/layout/fill_layout.h"
24 #include "ui/views/view.h" 24 #include "ui/views/view.h"
25 #include "ui/views/widget/widget.h" 25 #include "ui/views/widget/widget.h"
26 #include "ui/views/widget/widget_delegate.h" 26 #include "ui/views/widget/widget_delegate.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 break; 115 break;
116 case WAIT_FOR_DOUBLE_PRESS: 116 case WAIT_FOR_DOUBLE_PRESS:
117 state_ = EXITING; 117 state_ = EXITING;
118 CancelTimer(); 118 CancelTimer();
119 Hide(); 119 Hide();
120 WmShell::Get()->RecordUserMetricsAction(UMA_ACCEL_EXIT_SECOND_Q); 120 WmShell::Get()->RecordUserMetricsAction(UMA_ACCEL_EXIT_SECOND_Q);
121 WmShell::Get()->delegate()->Exit(); 121 WmShell::Get()->delegate()->Exit();
122 break; 122 break;
123 case EXITING: 123 case EXITING:
124 break; 124 break;
125 default:
126 NOTREACHED();
127 break;
128 } 125 }
129 } 126 }
130 127
131 void ExitWarningHandler::TimerAction() { 128 void ExitWarningHandler::TimerAction() {
132 Hide(); 129 Hide();
133 if (state_ == WAIT_FOR_DOUBLE_PRESS) 130 if (state_ == WAIT_FOR_DOUBLE_PRESS)
134 state_ = IDLE; 131 state_ = IDLE;
135 } 132 }
136 133
137 void ExitWarningHandler::StartTimer() { 134 void ExitWarningHandler::StartTimer() {
138 if (stub_timer_for_test_) 135 if (stub_timer_for_test_)
139 return; 136 return;
140 timer_.Start(FROM_HERE, 137 timer_.Start(FROM_HERE,
141 base::TimeDelta::FromMilliseconds(kTimeOutMilliseconds), this, 138 base::TimeDelta::FromMilliseconds(kTimeOutMilliseconds), this,
142 &ExitWarningHandler::TimerAction); 139 &ExitWarningHandler::TimerAction);
143 } 140 }
144 141
145 void ExitWarningHandler::CancelTimer() { 142 void ExitWarningHandler::CancelTimer() {
146 timer_.Stop(); 143 timer_.Stop();
147 } 144 }
148 145
149 void ExitWarningHandler::Show() { 146 void ExitWarningHandler::Show() {
150 if (widget_) 147 if (widget_)
151 return; 148 return;
152 aura::Window* root_window = Shell::GetTargetRootWindow(); 149 WmWindow* root_window = WmShell::Get()->GetRootWindowForNewWindows();
153 ExitWarningWidgetDelegateView* delegate = new ExitWarningWidgetDelegateView; 150 ExitWarningWidgetDelegateView* delegate = new ExitWarningWidgetDelegateView;
154 gfx::Size rs = root_window->bounds().size(); 151 gfx::Size rs = root_window->GetBounds().size();
155 gfx::Size ps = delegate->GetPreferredSize(); 152 gfx::Size ps = delegate->GetPreferredSize();
156 gfx::Rect bounds((rs.width() - ps.width()) / 2, 153 gfx::Rect bounds((rs.width() - ps.width()) / 2,
157 (rs.height() - ps.height()) / 3, ps.width(), ps.height()); 154 (rs.height() - ps.height()) / 3, ps.width(), ps.height());
158 views::Widget::InitParams params; 155 views::Widget::InitParams params;
159 params.type = views::Widget::InitParams::TYPE_POPUP; 156 params.type = views::Widget::InitParams::TYPE_POPUP;
160 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 157 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
161 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 158 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
162 params.accept_events = false; 159 params.accept_events = false;
163 params.keep_on_top = true; 160 params.keep_on_top = true;
164 params.remove_standard_frame = true; 161 params.remove_standard_frame = true;
165 params.delegate = delegate; 162 params.delegate = delegate;
166 params.bounds = bounds; 163 params.bounds = bounds;
167 params.parent = 164 params.name = "ExitWarningWindow";
168 Shell::GetContainer(root_window, kShellWindowId_SettingBubbleContainer);
169 widget_.reset(new views::Widget); 165 widget_.reset(new views::Widget);
166 root_window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer(
167 widget_.get(), kShellWindowId_SettingBubbleContainer, &params);
170 widget_->Init(params); 168 widget_->Init(params);
171 widget_->SetContentsView(delegate); 169 widget_->SetContentsView(delegate);
172 widget_->GetNativeView()->SetName("ExitWarningWindow");
173 widget_->Show(); 170 widget_->Show();
174 171
175 delegate->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); 172 delegate->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
176 } 173 }
177 174
178 void ExitWarningHandler::Hide() { 175 void ExitWarningHandler::Hide() {
179 widget_.reset(); 176 widget_.reset();
180 } 177 }
181 178
182 } // namespace ash 179 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698