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/views/fullscreen_exit_bubble.h" | 5 #include "chrome/browser/ui/views/fullscreen_exit_bubble.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 bool got_accelerator = frame->GetAccelerator(IDC_FULLSCREEN, &accelerator); | 126 bool got_accelerator = frame->GetAccelerator(IDC_FULLSCREEN, &accelerator); |
127 DCHECK(got_accelerator); | 127 DCHECK(got_accelerator); |
128 view_ = new FullscreenExitView( | 128 view_ = new FullscreenExitView( |
129 this, UTF16ToWideHack(accelerator.GetShortcutText())); | 129 this, UTF16ToWideHack(accelerator.GetShortcutText())); |
130 | 130 |
131 // Initialize the popup. | 131 // Initialize the popup. |
132 popup_ = new views::Widget; | 132 popup_ = new views::Widget; |
133 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 133 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
134 params.transparent = true; | 134 params.transparent = true; |
135 params.can_activate = false; | 135 params.can_activate = false; |
136 params.delete_on_destroy = false; | 136 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
137 params.parent = frame->GetNativeView(); | 137 params.parent = frame->GetNativeView(); |
138 params.bounds = GetPopupRect(false); | 138 params.bounds = GetPopupRect(false); |
139 popup_->Init(params); | 139 popup_->Init(params); |
140 popup_->SetContentsView(view_); | 140 popup_->SetContentsView(view_); |
141 popup_->SetOpacity(static_cast<unsigned char>(0xff * kOpacity)); | 141 popup_->SetOpacity(static_cast<unsigned char>(0xff * kOpacity)); |
142 popup_->Show(); // This does not activate the popup. | 142 popup_->Show(); // This does not activate the popup. |
143 | 143 |
144 // Start the initial delay timer and begin watching the mouse. | 144 // Start the initial delay timer and begin watching the mouse. |
145 initial_delay_.Start(base::TimeDelta::FromMilliseconds(kInitialDelayMs), this, | 145 initial_delay_.Start(base::TimeDelta::FromMilliseconds(kInitialDelayMs), this, |
146 &FullscreenExitBubble::CheckMousePosition); | 146 &FullscreenExitBubble::CheckMousePosition); |
147 gfx::Point cursor_pos = views::Screen::GetCursorScreenPoint(); | 147 gfx::Point cursor_pos = views::Screen::GetCursorScreenPoint(); |
148 last_mouse_pos_ = cursor_pos; | 148 last_mouse_pos_ = cursor_pos; |
149 views::View::ConvertPointToView(NULL, root_view_, &last_mouse_pos_); | 149 views::View::ConvertPointToView(NULL, root_view_, &last_mouse_pos_); |
150 mouse_position_checker_.Start( | 150 mouse_position_checker_.Start( |
151 base::TimeDelta::FromMilliseconds(1000 / kPositionCheckHz), this, | 151 base::TimeDelta::FromMilliseconds(1000 / kPositionCheckHz), this, |
152 &FullscreenExitBubble::CheckMousePosition); | 152 &FullscreenExitBubble::CheckMousePosition); |
153 } | 153 } |
154 | 154 |
155 FullscreenExitBubble::~FullscreenExitBubble() { | 155 FullscreenExitBubble::~FullscreenExitBubble() { |
156 // This is tricky. We may be in an ATL message handler stack, in which case | 156 // This is tricky. We may be in an ATL message handler stack, in which case |
157 // the popup cannot be deleted yet. We also can't blindly use | 157 // the popup cannot be deleted yet. We also can't set the popup's ownership |
158 // set_delete_on_destroy(true) on the popup to delete it when it closes, | 158 // model to NATIVE_WIDGET_OWNS_WIDGET because if the user closed the last tab |
159 // because if the user closed the last tab while in fullscreen mode, Windows | 159 // while in fullscreen mode, Windows has already destroyed the popup HWND by |
160 // has already destroyed the popup HWND by the time we get here, and thus | 160 // the time we get here, and thus either the popup will already have been |
161 // either the popup will already have been deleted (if we set this in our | 161 // deleted (if we set this in our constructor) or the popup will never get |
162 // constructor) or the popup will never get another OnFinalMessage() call (if | 162 // another OnFinalMessage() call (if not, as currently). So instead, we tell |
163 // not, as currently). So instead, we tell the popup to synchronously hide, | 163 // the popup to synchronously hide, and then asynchronously close and delete |
164 // and then asynchronously close and delete itself. | 164 // itself. |
165 popup_->Close(); | 165 popup_->Close(); |
166 MessageLoop::current()->DeleteSoon(FROM_HERE, popup_); | 166 MessageLoop::current()->DeleteSoon(FROM_HERE, popup_); |
167 } | 167 } |
168 | 168 |
169 void FullscreenExitBubble::LinkClicked(views::Link* source, int event_flags) { | 169 void FullscreenExitBubble::LinkClicked(views::Link* source, int event_flags) { |
170 delegate_->ExecuteCommand(IDC_FULLSCREEN); | 170 delegate_->ExecuteCommand(IDC_FULLSCREEN); |
171 } | 171 } |
172 | 172 |
173 void FullscreenExitBubble::AnimationProgressed( | 173 void FullscreenExitBubble::AnimationProgressed( |
174 const ui::Animation* animation) { | 174 const ui::Animation* animation) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 } | 252 } |
253 // NOTE: don't use the bounds of the root_view_. On linux changing window | 253 // NOTE: don't use the bounds of the root_view_. On linux changing window |
254 // size is async. Instead we use the size of the screen. | 254 // size is async. Instead we use the size of the screen. |
255 gfx::Rect screen_bounds = views::Screen::GetMonitorAreaNearestWindow( | 255 gfx::Rect screen_bounds = views::Screen::GetMonitorAreaNearestWindow( |
256 root_view_->GetWidget()->GetNativeView()); | 256 root_view_->GetWidget()->GetNativeView()); |
257 gfx::Point origin(screen_bounds.x() + | 257 gfx::Point origin(screen_bounds.x() + |
258 (screen_bounds.width() - size.width()) / 2, | 258 (screen_bounds.width() - size.width()) / 2, |
259 screen_bounds.y()); | 259 screen_bounds.y()); |
260 return gfx::Rect(origin, size); | 260 return gfx::Rect(origin, size); |
261 } | 261 } |
OLD | NEW |