| OLD | NEW |
| 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" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_delegate.h" | 8 #include "ash/shell_delegate.h" |
| 9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 base::string16 text_; | 93 base::string16 text_; |
| 94 base::string16 accessible_name_; | 94 base::string16 accessible_name_; |
| 95 gfx::Font font_; | 95 gfx::Font font_; |
| 96 int text_width_; | 96 int text_width_; |
| 97 int width_; | 97 int width_; |
| 98 int height_; | 98 int height_; |
| 99 | 99 |
| 100 DISALLOW_COPY_AND_ASSIGN(ExitWarningWidgetDelegateView); | 100 DISALLOW_COPY_AND_ASSIGN(ExitWarningWidgetDelegateView); |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 } // namespace | 103 } // namespace |
| 104 | 104 |
| 105 ExitWarningHandler::ExitWarningHandler() | 105 ExitWarningHandler::ExitWarningHandler() |
| 106 : state_(IDLE), | 106 : state_(IDLE), |
| 107 widget_(NULL), | |
| 108 stub_timer_for_test_(false) { | 107 stub_timer_for_test_(false) { |
| 109 } | 108 } |
| 110 | 109 |
| 111 ExitWarningHandler::~ExitWarningHandler() { | 110 ExitWarningHandler::~ExitWarningHandler() { |
| 112 // Note: If a timer is outstanding, it is stopped in its destructor. | 111 // Note: If a timer is outstanding, it is stopped in its destructor. |
| 113 Hide(); | 112 Hide(); |
| 114 } | 113 } |
| 115 | 114 |
| 116 void ExitWarningHandler::HandleAccelerator() { | 115 void ExitWarningHandler::HandleAccelerator() { |
| 117 ShellDelegate* shell_delegate = Shell::GetInstance()->delegate(); | 116 ShellDelegate* shell_delegate = Shell::GetInstance()->delegate(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 aura::RootWindow* root_window = Shell::GetActiveRootWindow(); | 161 aura::RootWindow* root_window = Shell::GetActiveRootWindow(); |
| 163 ExitWarningWidgetDelegateView* delegate = new ExitWarningWidgetDelegateView; | 162 ExitWarningWidgetDelegateView* delegate = new ExitWarningWidgetDelegateView; |
| 164 gfx::Size rs = root_window->bounds().size(); | 163 gfx::Size rs = root_window->bounds().size(); |
| 165 gfx::Size ps = delegate->GetPreferredSize(); | 164 gfx::Size ps = delegate->GetPreferredSize(); |
| 166 gfx::Rect bounds((rs.width() - ps.width()) / 2, | 165 gfx::Rect bounds((rs.width() - ps.width()) / 2, |
| 167 (rs.height() - ps.height()) / 3, | 166 (rs.height() - ps.height()) / 3, |
| 168 ps.width(), ps.height()); | 167 ps.width(), ps.height()); |
| 169 views::Widget::InitParams params; | 168 views::Widget::InitParams params; |
| 170 params.type = views::Widget::InitParams::TYPE_POPUP; | 169 params.type = views::Widget::InitParams::TYPE_POPUP; |
| 171 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 170 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 171 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 172 params.accept_events = false; | 172 params.accept_events = false; |
| 173 params.can_activate = false; | 173 params.can_activate = false; |
| 174 params.keep_on_top = true; | 174 params.keep_on_top = true; |
| 175 params.remove_standard_frame = true; | 175 params.remove_standard_frame = true; |
| 176 params.delegate = delegate; | 176 params.delegate = delegate; |
| 177 params.bounds = bounds; | 177 params.bounds = bounds; |
| 178 params.parent = Shell::GetContainer( | 178 params.parent = Shell::GetContainer( |
| 179 root_window, | 179 root_window, |
| 180 internal::kShellWindowId_SettingBubbleContainer); | 180 internal::kShellWindowId_SettingBubbleContainer); |
| 181 widget_ = new views::Widget; | 181 widget_.reset(new views::Widget); |
| 182 widget_->Init(params); | 182 widget_->Init(params); |
| 183 widget_->SetContentsView(delegate); | 183 widget_->SetContentsView(delegate); |
| 184 widget_->GetNativeView()->SetName("ExitWarningWindow"); | 184 widget_->GetNativeView()->SetName("ExitWarningWindow"); |
| 185 widget_->Show(); | 185 widget_->Show(); |
| 186 | 186 |
| 187 delegate->NotifyAccessibilityEvent(ui::AccessibilityTypes::EVENT_ALERT, true); | 187 delegate->NotifyAccessibilityEvent(ui::AccessibilityTypes::EVENT_ALERT, true); |
| 188 } | 188 } |
| 189 | 189 |
| 190 void ExitWarningHandler::Hide() { | 190 void ExitWarningHandler::Hide() { |
| 191 if (!widget_) | 191 widget_.reset(); |
| 192 return; | |
| 193 widget_->Close(); | |
| 194 widget_ = NULL; | |
| 195 } | 192 } |
| 196 | 193 |
| 197 } // namespace ash | 194 } // namespace ash |
| OLD | NEW |