OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_views.h" | 5 #include "chrome/browser/ui/views/exclusive_access_bubble_views.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 11 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
12 #include "chrome/browser/ui/views/frame/browser_view.h" | 12 #include "chrome/browser/ui/views/frame/browser_view.h" |
13 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" | 13 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" |
14 #include "chrome/browser/ui/views/frame/top_container_view.h" | 14 #include "chrome/browser/ui/views/frame/top_container_view.h" |
15 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
(...skipping 12 matching lines...) Expand all Loading... |
28 #include "ui/views/layout/box_layout.h" | 28 #include "ui/views/layout/box_layout.h" |
29 #include "ui/views/layout/grid_layout.h" | 29 #include "ui/views/layout/grid_layout.h" |
30 #include "ui/views/view.h" | 30 #include "ui/views/view.h" |
31 #include "ui/views/widget/widget.h" | 31 #include "ui/views/widget/widget.h" |
32 #include "url/gurl.h" | 32 #include "url/gurl.h" |
33 | 33 |
34 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
35 #include "ui/base/l10n/l10n_util_win.h" | 35 #include "ui/base/l10n/l10n_util_win.h" |
36 #endif | 36 #endif |
37 | 37 |
38 // FullscreenExitView ---------------------------------------------------------- | 38 // ExclusiveAccessView --------------------------------------------------------- |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 // Space between the site info label and the buttons / link. | 42 // Space between the site info label and the buttons / link. |
43 const int kMiddlePaddingPx = 30; | 43 const int kMiddlePaddingPx = 30; |
44 | 44 |
45 class ButtonView : public views::View { | 45 class ButtonView : public views::View { |
46 public: | 46 public: |
47 ButtonView(views::ButtonListener* listener, int between_button_spacing); | 47 ButtonView(views::ButtonListener* listener, int between_button_spacing); |
48 ~ButtonView() override; | 48 ~ButtonView() override; |
49 | 49 |
50 // Returns an empty size when the view is not visible. | 50 // Returns an empty size when the view is not visible. |
51 gfx::Size GetPreferredSize() const override; | 51 gfx::Size GetPreferredSize() const override; |
52 | 52 |
53 views::LabelButton* accept_button() const { return accept_button_; } | 53 views::LabelButton* accept_button() const { return accept_button_; } |
54 views::LabelButton* deny_button() const { return deny_button_; } | 54 views::LabelButton* deny_button() const { return deny_button_; } |
55 | 55 |
56 private: | 56 private: |
57 views::LabelButton* accept_button_; | 57 views::LabelButton* accept_button_; |
58 views::LabelButton* deny_button_; | 58 views::LabelButton* deny_button_; |
59 | 59 |
60 DISALLOW_COPY_AND_ASSIGN(ButtonView); | 60 DISALLOW_COPY_AND_ASSIGN(ButtonView); |
61 }; | 61 }; |
62 | 62 |
63 ButtonView::ButtonView(views::ButtonListener* listener, | 63 ButtonView::ButtonView(views::ButtonListener* listener, |
64 int between_button_spacing) | 64 int between_button_spacing) |
65 : accept_button_(NULL), | 65 : accept_button_(NULL), deny_button_(NULL) { |
66 deny_button_(NULL) { | |
67 accept_button_ = new views::LabelButton(listener, base::string16()); | 66 accept_button_ = new views::LabelButton(listener, base::string16()); |
68 accept_button_->SetStyle(views::Button::STYLE_BUTTON); | 67 accept_button_->SetStyle(views::Button::STYLE_BUTTON); |
69 accept_button_->SetFocusable(false); | 68 accept_button_->SetFocusable(false); |
70 AddChildView(accept_button_); | 69 AddChildView(accept_button_); |
71 | 70 |
72 deny_button_ = new views::LabelButton(listener, base::string16()); | 71 deny_button_ = new views::LabelButton(listener, base::string16()); |
73 deny_button_->SetStyle(views::Button::STYLE_BUTTON); | 72 deny_button_->SetStyle(views::Button::STYLE_BUTTON); |
74 deny_button_->SetFocusable(false); | 73 deny_button_->SetFocusable(false); |
75 AddChildView(deny_button_); | 74 AddChildView(deny_button_); |
76 | 75 |
77 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, | 76 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, |
78 between_button_spacing)); | 77 between_button_spacing)); |
79 } | 78 } |
80 | 79 |
81 ButtonView::~ButtonView() { | 80 ButtonView::~ButtonView() { |
82 } | 81 } |
83 | 82 |
84 gfx::Size ButtonView::GetPreferredSize() const { | 83 gfx::Size ButtonView::GetPreferredSize() const { |
85 return visible() ? views::View::GetPreferredSize() : gfx::Size(); | 84 return visible() ? views::View::GetPreferredSize() : gfx::Size(); |
86 } | 85 } |
87 | 86 |
88 } // namespace | 87 } // namespace |
89 | 88 |
90 class FullscreenExitBubbleViews::FullscreenExitView | 89 class ExclusiveAccessBubbleViews::ExclusiveAccessView |
91 : public views::View, | 90 : public views::View, |
92 public views::ButtonListener, | 91 public views::ButtonListener, |
93 public views::LinkListener { | 92 public views::LinkListener { |
94 public: | 93 public: |
95 FullscreenExitView(FullscreenExitBubbleViews* bubble, | 94 ExclusiveAccessView(ExclusiveAccessBubbleViews* bubble, |
96 const base::string16& accelerator, | 95 const base::string16& accelerator, |
97 const GURL& url, | 96 const GURL& url, |
98 FullscreenExitBubbleType bubble_type); | 97 ExclusiveAccessBubbleType bubble_type); |
99 ~FullscreenExitView() override; | 98 ~ExclusiveAccessView() override; |
100 | 99 |
101 // views::ButtonListener | 100 // views::ButtonListener |
102 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 101 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
103 | 102 |
104 // views::LinkListener | 103 // views::LinkListener |
105 void LinkClicked(views::Link* source, int event_flags) override; | 104 void LinkClicked(views::Link* source, int event_flags) override; |
106 | 105 |
107 void UpdateContent(const GURL& url, FullscreenExitBubbleType bubble_type); | 106 void UpdateContent(const GURL& url, ExclusiveAccessBubbleType bubble_type); |
108 | 107 |
109 private: | 108 private: |
110 FullscreenExitBubbleViews* bubble_; | 109 ExclusiveAccessBubbleViews* bubble_; |
111 | 110 |
112 // Clickable hint text for exiting fullscreen mode. | 111 // Clickable hint text for exiting fullscreen mode. |
113 views::Link* link_; | 112 views::Link* link_; |
114 // Instruction for exiting mouse lock. | 113 // Instruction for exiting mouse lock. |
115 views::Label* mouse_lock_exit_instruction_; | 114 views::Label* mouse_lock_exit_instruction_; |
116 // Informational label: 'www.foo.com has gone fullscreen'. | 115 // Informational label: 'www.foo.com has gone fullscreen'. |
117 views::Label* message_label_; | 116 views::Label* message_label_; |
118 ButtonView* button_view_; | 117 ButtonView* button_view_; |
119 const base::string16 browser_fullscreen_exit_accelerator_; | 118 const base::string16 browser_fullscreen_exit_accelerator_; |
120 | 119 |
121 DISALLOW_COPY_AND_ASSIGN(FullscreenExitView); | 120 DISALLOW_COPY_AND_ASSIGN(ExclusiveAccessView); |
122 }; | 121 }; |
123 | 122 |
124 FullscreenExitBubbleViews::FullscreenExitView::FullscreenExitView( | 123 ExclusiveAccessBubbleViews::ExclusiveAccessView::ExclusiveAccessView( |
125 FullscreenExitBubbleViews* bubble, | 124 ExclusiveAccessBubbleViews* bubble, |
126 const base::string16& accelerator, | 125 const base::string16& accelerator, |
127 const GURL& url, | 126 const GURL& url, |
128 FullscreenExitBubbleType bubble_type) | 127 ExclusiveAccessBubbleType bubble_type) |
129 : bubble_(bubble), | 128 : bubble_(bubble), |
130 link_(NULL), | 129 link_(NULL), |
131 mouse_lock_exit_instruction_(NULL), | 130 mouse_lock_exit_instruction_(NULL), |
132 message_label_(NULL), | 131 message_label_(NULL), |
133 button_view_(NULL), | 132 button_view_(NULL), |
134 browser_fullscreen_exit_accelerator_(accelerator) { | 133 browser_fullscreen_exit_accelerator_(accelerator) { |
135 scoped_ptr<views::BubbleBorder> bubble_border( | 134 scoped_ptr<views::BubbleBorder> bubble_border( |
136 new views::BubbleBorder(views::BubbleBorder::NONE, | 135 new views::BubbleBorder(views::BubbleBorder::NONE, |
137 views::BubbleBorder::BIG_SHADOW, | 136 views::BubbleBorder::BIG_SHADOW, SK_ColorWHITE)); |
138 SK_ColorWHITE)); | |
139 set_background(new views::BubbleBackground(bubble_border.get())); | 137 set_background(new views::BubbleBackground(bubble_border.get())); |
140 SetBorder(bubble_border.Pass()); | 138 SetBorder(bubble_border.Pass()); |
141 SetFocusable(false); | 139 SetFocusable(false); |
142 | 140 |
143 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 141 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
144 const gfx::FontList& medium_font_list = | 142 const gfx::FontList& medium_font_list = |
145 rb.GetFontList(ui::ResourceBundle::MediumFont); | 143 rb.GetFontList(ui::ResourceBundle::MediumFont); |
146 message_label_ = new views::Label(base::string16(), medium_font_list); | 144 message_label_ = new views::Label(base::string16(), medium_font_list); |
147 | 145 |
148 mouse_lock_exit_instruction_ = | 146 mouse_lock_exit_instruction_ = |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 layout->AddView(link_); | 186 layout->AddView(link_); |
189 | 187 |
190 gfx::Insets padding(kPaddingPx, kPaddingPx, kPaddingPx, kPaddingPx); | 188 gfx::Insets padding(kPaddingPx, kPaddingPx, kPaddingPx, kPaddingPx); |
191 padding += GetInsets(); | 189 padding += GetInsets(); |
192 layout->SetInsets(padding); | 190 layout->SetInsets(padding); |
193 SetLayoutManager(layout); | 191 SetLayoutManager(layout); |
194 | 192 |
195 UpdateContent(url, bubble_type); | 193 UpdateContent(url, bubble_type); |
196 } | 194 } |
197 | 195 |
198 FullscreenExitBubbleViews::FullscreenExitView::~FullscreenExitView() { | 196 ExclusiveAccessBubbleViews::ExclusiveAccessView::~ExclusiveAccessView() { |
199 } | 197 } |
200 | 198 |
201 void FullscreenExitBubbleViews::FullscreenExitView::ButtonPressed( | 199 void ExclusiveAccessBubbleViews::ExclusiveAccessView::ButtonPressed( |
202 views::Button* sender, | 200 views::Button* sender, |
203 const ui::Event& event) { | 201 const ui::Event& event) { |
204 if (sender == button_view_->accept_button()) | 202 if (sender == button_view_->accept_button()) |
205 bubble_->Accept(); | 203 bubble_->Accept(); |
206 else | 204 else |
207 bubble_->Cancel(); | 205 bubble_->Cancel(); |
208 } | 206 } |
209 | 207 |
210 void FullscreenExitBubbleViews::FullscreenExitView::LinkClicked( | 208 void ExclusiveAccessBubbleViews::ExclusiveAccessView::LinkClicked( |
211 views::Link* link, | 209 views::Link* link, |
212 int event_flags) { | 210 int event_flags) { |
213 bubble_->ToggleFullscreen(); | 211 bubble_->ToggleFullscreen(); |
214 } | 212 } |
215 | 213 |
216 void FullscreenExitBubbleViews::FullscreenExitView::UpdateContent( | 214 void ExclusiveAccessBubbleViews::ExclusiveAccessView::UpdateContent( |
217 const GURL& url, | 215 const GURL& url, |
218 FullscreenExitBubbleType bubble_type) { | 216 ExclusiveAccessBubbleType bubble_type) { |
219 DCHECK_NE(FEB_TYPE_NONE, bubble_type); | 217 DCHECK_NE(EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE, bubble_type); |
220 | 218 |
221 message_label_->SetText(bubble_->GetCurrentMessageText()); | 219 message_label_->SetText(bubble_->GetCurrentMessageText()); |
222 if (fullscreen_bubble::ShowButtonsForType(bubble_type)) { | 220 if (exclusive_access_bubble::ShowButtonsForType(bubble_type)) { |
223 link_->SetVisible(false); | 221 link_->SetVisible(false); |
224 mouse_lock_exit_instruction_->SetVisible(false); | 222 mouse_lock_exit_instruction_->SetVisible(false); |
225 button_view_->SetVisible(true); | 223 button_view_->SetVisible(true); |
226 button_view_->deny_button()->SetText(bubble_->GetCurrentDenyButtonText()); | 224 button_view_->deny_button()->SetText(bubble_->GetCurrentDenyButtonText()); |
227 button_view_->deny_button()->SetMinSize(gfx::Size()); | 225 button_view_->deny_button()->SetMinSize(gfx::Size()); |
228 } else { | 226 } else { |
229 bool link_visible = true; | 227 bool link_visible = true; |
230 base::string16 accelerator; | 228 base::string16 accelerator; |
231 if (bubble_type == FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION || | 229 if (bubble_type == |
232 bubble_type == FEB_TYPE_BROWSER_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION) { | 230 EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION || |
| 231 bubble_type == |
| 232 EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION)
{ |
233 accelerator = browser_fullscreen_exit_accelerator_; | 233 accelerator = browser_fullscreen_exit_accelerator_; |
234 } else if (bubble_type == FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION) { | 234 } else if (bubble_type == |
| 235 EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION) { |
235 accelerator = l10n_util::GetStringUTF16(IDS_APP_ESC_KEY); | 236 accelerator = l10n_util::GetStringUTF16(IDS_APP_ESC_KEY); |
236 } else { | 237 } else { |
237 link_visible = false; | 238 link_visible = false; |
238 } | 239 } |
239 #if !defined(OS_CHROMEOS) | 240 #if !defined(OS_CHROMEOS) |
240 if (link_visible) { | 241 if (link_visible) { |
241 link_->SetText( | 242 link_->SetText(l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_MODE) + |
242 l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_MODE) + | 243 base::UTF8ToUTF16(" ") + |
243 base::UTF8ToUTF16(" ") + | 244 l10n_util::GetStringFUTF16( |
244 l10n_util::GetStringFUTF16(IDS_EXIT_FULLSCREEN_MODE_ACCELERATOR, | 245 IDS_EXIT_FULLSCREEN_MODE_ACCELERATOR, accelerator)); |
245 accelerator)); | |
246 } | 246 } |
247 #endif | 247 #endif |
248 link_->SetVisible(link_visible); | 248 link_->SetVisible(link_visible); |
249 mouse_lock_exit_instruction_->SetVisible(!link_visible); | 249 mouse_lock_exit_instruction_->SetVisible(!link_visible); |
250 button_view_->SetVisible(false); | 250 button_view_->SetVisible(false); |
251 } | 251 } |
252 } | 252 } |
253 | 253 |
| 254 // ExclusiveAccessBubbleViews -------------------------------------------------- |
254 | 255 |
255 // FullscreenExitBubbleViews --------------------------------------------------- | 256 ExclusiveAccessBubbleViews::ExclusiveAccessBubbleViews( |
256 | |
257 FullscreenExitBubbleViews::FullscreenExitBubbleViews( | |
258 BrowserView* browser_view, | 257 BrowserView* browser_view, |
259 const GURL& url, | 258 const GURL& url, |
260 FullscreenExitBubbleType bubble_type) | 259 ExclusiveAccessBubbleType bubble_type) |
261 : FullscreenExitBubble(browser_view->browser(), url, bubble_type), | 260 : ExclusiveAccessBubble(browser_view->browser(), url, bubble_type), |
262 browser_view_(browser_view), | 261 browser_view_(browser_view), |
263 popup_(NULL), | 262 popup_(NULL), |
264 animation_(new gfx::SlideAnimation(this)), | 263 animation_(new gfx::SlideAnimation(this)), |
265 animated_attribute_(ANIMATED_ATTRIBUTE_BOUNDS) { | 264 animated_attribute_(ANIMATED_ATTRIBUTE_BOUNDS) { |
266 animation_->Reset(1); | 265 animation_->Reset(1); |
267 | 266 |
268 // Create the contents view. | 267 // Create the contents view. |
269 ui::Accelerator accelerator(ui::VKEY_UNKNOWN, ui::EF_NONE); | 268 ui::Accelerator accelerator(ui::VKEY_UNKNOWN, ui::EF_NONE); |
270 bool got_accelerator = browser_view_->GetWidget()->GetAccelerator( | 269 bool got_accelerator = |
271 IDC_FULLSCREEN, &accelerator); | 270 browser_view_->GetWidget()->GetAccelerator(IDC_FULLSCREEN, &accelerator); |
272 DCHECK(got_accelerator); | 271 DCHECK(got_accelerator); |
273 view_ = new FullscreenExitView( | 272 view_ = new ExclusiveAccessView(this, accelerator.GetShortcutText(), url, |
274 this, accelerator.GetShortcutText(), url, bubble_type_); | 273 bubble_type_); |
275 | 274 |
276 // TODO(yzshen): Change to use the new views bubble, BubbleDelegateView. | 275 // TODO(yzshen): Change to use the new views bubble, BubbleDelegateView. |
277 // TODO(pkotwicz): When this becomes a views bubble, make sure that this | 276 // TODO(pkotwicz): When this becomes a views bubble, make sure that this |
278 // bubble is ignored by ImmersiveModeControllerAsh::BubbleManager. | 277 // bubble is ignored by ImmersiveModeControllerAsh::BubbleManager. |
279 // Initialize the popup. | 278 // Initialize the popup. |
280 popup_ = new views::Widget; | 279 popup_ = new views::Widget; |
281 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 280 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
282 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 281 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
283 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 282 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
284 params.parent = browser_view_->GetWidget()->GetNativeView(); | 283 params.parent = browser_view_->GetWidget()->GetNativeView(); |
285 params.bounds = GetPopupRect(false); | 284 params.bounds = GetPopupRect(false); |
286 popup_->Init(params); | 285 popup_->Init(params); |
287 gfx::Size size = GetPopupRect(true).size(); | 286 gfx::Size size = GetPopupRect(true).size(); |
288 popup_->SetContentsView(view_); | 287 popup_->SetContentsView(view_); |
289 // We set layout manager to NULL to prevent the widget from sizing its | 288 // We set layout manager to NULL to prevent the widget from sizing its |
290 // contents to the same size as itself. This prevents the widget contents from | 289 // contents to the same size as itself. This prevents the widget contents from |
291 // shrinking while we animate the height of the popup to give the impression | 290 // shrinking while we animate the height of the popup to give the impression |
292 // that it is sliding off the top of the screen. | 291 // that it is sliding off the top of the screen. |
293 popup_->GetRootView()->SetLayoutManager(NULL); | 292 popup_->GetRootView()->SetLayoutManager(NULL); |
294 view_->SetBounds(0, 0, size.width(), size.height()); | 293 view_->SetBounds(0, 0, size.width(), size.height()); |
295 popup_->ShowInactive(); // This does not activate the popup. | 294 popup_->ShowInactive(); // This does not activate the popup. |
296 | 295 |
297 popup_->AddObserver(this); | 296 popup_->AddObserver(this); |
298 | 297 |
299 registrar_.Add( | 298 registrar_.Add(this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
300 this, | 299 content::Source<FullscreenController>( |
301 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | 300 browser_view_->browser()->fullscreen_controller())); |
302 content::Source<FullscreenController>( | |
303 browser_view_->browser()->fullscreen_controller())); | |
304 | 301 |
305 UpdateForImmersiveState(); | 302 UpdateForImmersiveState(); |
306 } | 303 } |
307 | 304 |
308 FullscreenExitBubbleViews::~FullscreenExitBubbleViews() { | 305 ExclusiveAccessBubbleViews::~ExclusiveAccessBubbleViews() { |
309 popup_->RemoveObserver(this); | 306 popup_->RemoveObserver(this); |
310 | 307 |
311 // This is tricky. We may be in an ATL message handler stack, in which case | 308 // This is tricky. We may be in an ATL message handler stack, in which case |
312 // the popup cannot be deleted yet. We also can't set the popup's ownership | 309 // the popup cannot be deleted yet. We also can't set the popup's ownership |
313 // model to NATIVE_WIDGET_OWNS_WIDGET because if the user closed the last tab | 310 // model to NATIVE_WIDGET_OWNS_WIDGET because if the user closed the last tab |
314 // while in fullscreen mode, Windows has already destroyed the popup HWND by | 311 // while in fullscreen mode, Windows has already destroyed the popup HWND by |
315 // the time we get here, and thus either the popup will already have been | 312 // the time we get here, and thus either the popup will already have been |
316 // deleted (if we set this in our constructor) or the popup will never get | 313 // deleted (if we set this in our constructor) or the popup will never get |
317 // another OnFinalMessage() call (if not, as currently). So instead, we tell | 314 // another OnFinalMessage() call (if not, as currently). So instead, we tell |
318 // the popup to synchronously hide, and then asynchronously close and delete | 315 // the popup to synchronously hide, and then asynchronously close and delete |
319 // itself. | 316 // itself. |
320 popup_->Close(); | 317 popup_->Close(); |
321 base::MessageLoop::current()->DeleteSoon(FROM_HERE, popup_); | 318 base::MessageLoop::current()->DeleteSoon(FROM_HERE, popup_); |
322 } | 319 } |
323 | 320 |
324 void FullscreenExitBubbleViews::UpdateContent( | 321 void ExclusiveAccessBubbleViews::UpdateContent( |
325 const GURL& url, | 322 const GURL& url, |
326 FullscreenExitBubbleType bubble_type) { | 323 ExclusiveAccessBubbleType bubble_type) { |
327 DCHECK_NE(FEB_TYPE_NONE, bubble_type); | 324 DCHECK_NE(EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE, bubble_type); |
328 if (bubble_type_ == bubble_type && url_ == url) | 325 if (bubble_type_ == bubble_type && url_ == url) |
329 return; | 326 return; |
330 | 327 |
331 url_ = url; | 328 url_ = url; |
332 bubble_type_ = bubble_type; | 329 bubble_type_ = bubble_type; |
333 view_->UpdateContent(url_, bubble_type_); | 330 view_->UpdateContent(url_, bubble_type_); |
334 | 331 |
335 gfx::Size size = GetPopupRect(true).size(); | 332 gfx::Size size = GetPopupRect(true).size(); |
336 view_->SetSize(size); | 333 view_->SetSize(size); |
337 popup_->SetBounds(GetPopupRect(false)); | 334 popup_->SetBounds(GetPopupRect(false)); |
338 Show(); | 335 Show(); |
339 | 336 |
340 // Stop watching the mouse even if UpdateMouseWatcher() will start watching | 337 // Stop watching the mouse even if UpdateMouseWatcher() will start watching |
341 // it again so that the popup with the new content is visible for at least | 338 // it again so that the popup with the new content is visible for at least |
342 // |kInitialDelayMs|. | 339 // |kInitialDelayMs|. |
343 StopWatchingMouse(); | 340 StopWatchingMouse(); |
344 | 341 |
345 UpdateMouseWatcher(); | 342 UpdateMouseWatcher(); |
346 } | 343 } |
347 | 344 |
348 void FullscreenExitBubbleViews::RepositionIfVisible() { | 345 void ExclusiveAccessBubbleViews::RepositionIfVisible() { |
349 if (popup_->IsVisible()) | 346 if (popup_->IsVisible()) |
350 UpdateBounds(); | 347 UpdateBounds(); |
351 } | 348 } |
352 | 349 |
353 void FullscreenExitBubbleViews::UpdateMouseWatcher() { | 350 void ExclusiveAccessBubbleViews::UpdateMouseWatcher() { |
354 bool should_watch_mouse = false; | 351 bool should_watch_mouse = false; |
355 if (popup_->IsVisible()) | 352 if (popup_->IsVisible()) |
356 should_watch_mouse = !fullscreen_bubble::ShowButtonsForType(bubble_type_); | 353 should_watch_mouse = |
| 354 !exclusive_access_bubble::ShowButtonsForType(bubble_type_); |
357 else | 355 else |
358 should_watch_mouse = CanMouseTriggerSlideIn(); | 356 should_watch_mouse = CanMouseTriggerSlideIn(); |
359 | 357 |
360 if (should_watch_mouse == IsWatchingMouse()) | 358 if (should_watch_mouse == IsWatchingMouse()) |
361 return; | 359 return; |
362 | 360 |
363 if (should_watch_mouse) | 361 if (should_watch_mouse) |
364 StartWatchingMouse(); | 362 StartWatchingMouse(); |
365 else | 363 else |
366 StopWatchingMouse(); | 364 StopWatchingMouse(); |
367 } | 365 } |
368 | 366 |
369 void FullscreenExitBubbleViews::UpdateForImmersiveState() { | 367 void ExclusiveAccessBubbleViews::UpdateForImmersiveState() { |
370 AnimatedAttribute expected_animated_attribute = | 368 AnimatedAttribute expected_animated_attribute = |
371 browser_view_->immersive_mode_controller()->IsEnabled() ? | 369 browser_view_->immersive_mode_controller()->IsEnabled() |
372 ANIMATED_ATTRIBUTE_OPACITY : ANIMATED_ATTRIBUTE_BOUNDS; | 370 ? ANIMATED_ATTRIBUTE_OPACITY |
| 371 : ANIMATED_ATTRIBUTE_BOUNDS; |
373 if (animated_attribute_ != expected_animated_attribute) { | 372 if (animated_attribute_ != expected_animated_attribute) { |
374 // If an animation is currently in progress, skip to the end because | 373 // If an animation is currently in progress, skip to the end because |
375 // switching the animated attribute midway through the animation looks | 374 // switching the animated attribute midway through the animation looks |
376 // weird. | 375 // weird. |
377 animation_->End(); | 376 animation_->End(); |
378 | 377 |
379 animated_attribute_ = expected_animated_attribute; | 378 animated_attribute_ = expected_animated_attribute; |
380 | 379 |
381 // We may have finished hiding |popup_|. However, the bounds animation | 380 // We may have finished hiding |popup_|. However, the bounds animation |
382 // assumes |popup_| has the opacity when it is fully shown and the opacity | 381 // assumes |popup_| has the opacity when it is fully shown and the opacity |
383 // animation assumes |popup_| has the bounds when |popup_| is fully shown. | 382 // animation assumes |popup_| has the bounds when |popup_| is fully shown. |
384 if (animated_attribute_ == ANIMATED_ATTRIBUTE_BOUNDS) | 383 if (animated_attribute_ == ANIMATED_ATTRIBUTE_BOUNDS) |
385 popup_->SetOpacity(255); | 384 popup_->SetOpacity(255); |
386 else | 385 else |
387 UpdateBounds(); | 386 UpdateBounds(); |
388 } | 387 } |
389 | 388 |
390 UpdateMouseWatcher(); | 389 UpdateMouseWatcher(); |
391 } | 390 } |
392 | 391 |
393 void FullscreenExitBubbleViews::UpdateBounds() { | 392 void ExclusiveAccessBubbleViews::UpdateBounds() { |
394 gfx::Rect popup_rect(GetPopupRect(false)); | 393 gfx::Rect popup_rect(GetPopupRect(false)); |
395 if (!popup_rect.IsEmpty()) { | 394 if (!popup_rect.IsEmpty()) { |
396 popup_->SetBounds(popup_rect); | 395 popup_->SetBounds(popup_rect); |
397 view_->SetY(popup_rect.height() - view_->height()); | 396 view_->SetY(popup_rect.height() - view_->height()); |
398 } | 397 } |
399 } | 398 } |
400 | 399 |
401 views::View* FullscreenExitBubbleViews::GetBrowserRootView() const { | 400 views::View* ExclusiveAccessBubbleViews::GetBrowserRootView() const { |
402 return browser_view_->GetWidget()->GetRootView(); | 401 return browser_view_->GetWidget()->GetRootView(); |
403 } | 402 } |
404 | 403 |
405 void FullscreenExitBubbleViews::AnimationProgressed( | 404 void ExclusiveAccessBubbleViews::AnimationProgressed( |
406 const gfx::Animation* animation) { | 405 const gfx::Animation* animation) { |
407 if (animated_attribute_ == ANIMATED_ATTRIBUTE_OPACITY) { | 406 if (animated_attribute_ == ANIMATED_ATTRIBUTE_OPACITY) { |
408 int opacity = animation_->CurrentValueBetween(0, 255); | 407 int opacity = animation_->CurrentValueBetween(0, 255); |
409 if (opacity == 0) { | 408 if (opacity == 0) { |
410 popup_->Hide(); | 409 popup_->Hide(); |
411 } else { | 410 } else { |
412 popup_->Show(); | 411 popup_->Show(); |
413 popup_->SetOpacity(opacity); | 412 popup_->SetOpacity(opacity); |
414 } | 413 } |
415 } else { | 414 } else { |
416 if (GetPopupRect(false).IsEmpty()) { | 415 if (GetPopupRect(false).IsEmpty()) { |
417 popup_->Hide(); | 416 popup_->Hide(); |
418 } else { | 417 } else { |
419 UpdateBounds(); | 418 UpdateBounds(); |
420 popup_->Show(); | 419 popup_->Show(); |
421 } | 420 } |
422 } | 421 } |
423 } | 422 } |
424 | 423 |
425 void FullscreenExitBubbleViews::AnimationEnded( | 424 void ExclusiveAccessBubbleViews::AnimationEnded( |
426 const gfx::Animation* animation) { | 425 const gfx::Animation* animation) { |
427 AnimationProgressed(animation); | 426 AnimationProgressed(animation); |
428 } | 427 } |
429 | 428 |
430 gfx::Rect FullscreenExitBubbleViews::GetPopupRect( | 429 gfx::Rect ExclusiveAccessBubbleViews::GetPopupRect( |
431 bool ignore_animation_state) const { | 430 bool ignore_animation_state) const { |
432 gfx::Size size(view_->GetPreferredSize()); | 431 gfx::Size size(view_->GetPreferredSize()); |
433 // NOTE: don't use the bounds of the root_view_. On linux GTK changing window | 432 // NOTE: don't use the bounds of the root_view_. On linux GTK changing window |
434 // size is async. Instead we use the size of the screen. | 433 // size is async. Instead we use the size of the screen. |
435 gfx::Screen* screen = | 434 gfx::Screen* screen = |
436 gfx::Screen::GetScreenFor(browser_view_->GetWidget()->GetNativeView()); | 435 gfx::Screen::GetScreenFor(browser_view_->GetWidget()->GetNativeView()); |
437 gfx::Rect screen_bounds = screen->GetDisplayNearestWindow( | 436 gfx::Rect screen_bounds = |
438 browser_view_->GetWidget()->GetNativeView()).bounds(); | 437 screen->GetDisplayNearestWindow( |
| 438 browser_view_->GetWidget()->GetNativeView()).bounds(); |
439 int x = screen_bounds.x() + (screen_bounds.width() - size.width()) / 2; | 439 int x = screen_bounds.x() + (screen_bounds.width() - size.width()) / 2; |
440 | 440 |
441 int top_container_bottom = screen_bounds.y(); | 441 int top_container_bottom = screen_bounds.y(); |
442 if (browser_view_->immersive_mode_controller()->IsEnabled()) { | 442 if (browser_view_->immersive_mode_controller()->IsEnabled()) { |
443 // Skip querying the top container height in non-immersive fullscreen | 443 // Skip querying the top container height in non-immersive fullscreen |
444 // because: | 444 // because: |
445 // - The top container height is always zero in non-immersive fullscreen. | 445 // - The top container height is always zero in non-immersive fullscreen. |
446 // - Querying the top container height may return the height before entering | 446 // - Querying the top container height may return the height before entering |
447 // fullscreen because layout is disabled while entering fullscreen. | 447 // fullscreen because layout is disabled while entering fullscreen. |
448 // A visual glitch due to the delayed layout is avoided in immersive | 448 // A visual glitch due to the delayed layout is avoided in immersive |
449 // fullscreen because entering fullscreen starts with the top container | 449 // fullscreen because entering fullscreen starts with the top container |
450 // revealed. When revealed, the top container has the same height as before | 450 // revealed. When revealed, the top container has the same height as before |
451 // entering fullscreen. | 451 // entering fullscreen. |
452 top_container_bottom = | 452 top_container_bottom = |
453 browser_view_->top_container()->GetBoundsInScreen().bottom(); | 453 browser_view_->top_container()->GetBoundsInScreen().bottom(); |
454 } | 454 } |
455 int y = top_container_bottom + kPopupTopPx; | 455 int y = top_container_bottom + kPopupTopPx; |
456 | 456 |
457 if (!ignore_animation_state && | 457 if (!ignore_animation_state && |
458 animated_attribute_ == ANIMATED_ATTRIBUTE_BOUNDS) { | 458 animated_attribute_ == ANIMATED_ATTRIBUTE_BOUNDS) { |
459 int total_height = size.height() + kPopupTopPx; | 459 int total_height = size.height() + kPopupTopPx; |
460 int popup_bottom = animation_->CurrentValueBetween(total_height, 0); | 460 int popup_bottom = animation_->CurrentValueBetween(total_height, 0); |
461 int y_offset = std::min(popup_bottom, kPopupTopPx); | 461 int y_offset = std::min(popup_bottom, kPopupTopPx); |
462 size.set_height(size.height() - popup_bottom + y_offset); | 462 size.set_height(size.height() - popup_bottom + y_offset); |
463 y -= y_offset; | 463 y -= y_offset; |
464 } | 464 } |
465 return gfx::Rect(gfx::Point(x, y), size); | 465 return gfx::Rect(gfx::Point(x, y), size); |
466 } | 466 } |
467 | 467 |
468 gfx::Point FullscreenExitBubbleViews::GetCursorScreenPoint() { | 468 gfx::Point ExclusiveAccessBubbleViews::GetCursorScreenPoint() { |
469 gfx::Point cursor_pos = gfx::Screen::GetScreenFor( | 469 gfx::Point cursor_pos = |
470 browser_view_->GetWidget()->GetNativeView())->GetCursorScreenPoint(); | 470 gfx::Screen::GetScreenFor(browser_view_->GetWidget()->GetNativeView()) |
| 471 ->GetCursorScreenPoint(); |
471 views::View::ConvertPointFromScreen(GetBrowserRootView(), &cursor_pos); | 472 views::View::ConvertPointFromScreen(GetBrowserRootView(), &cursor_pos); |
472 return cursor_pos; | 473 return cursor_pos; |
473 } | 474 } |
474 | 475 |
475 bool FullscreenExitBubbleViews::WindowContainsPoint(gfx::Point pos) { | 476 bool ExclusiveAccessBubbleViews::WindowContainsPoint(gfx::Point pos) { |
476 return GetBrowserRootView()->HitTestPoint(pos); | 477 return GetBrowserRootView()->HitTestPoint(pos); |
477 } | 478 } |
478 | 479 |
479 bool FullscreenExitBubbleViews::IsWindowActive() { | 480 bool ExclusiveAccessBubbleViews::IsWindowActive() { |
480 return browser_view_->GetWidget()->IsActive(); | 481 return browser_view_->GetWidget()->IsActive(); |
481 } | 482 } |
482 | 483 |
483 void FullscreenExitBubbleViews::Hide() { | 484 void ExclusiveAccessBubbleViews::Hide() { |
484 animation_->SetSlideDuration(kSlideOutDurationMs); | 485 animation_->SetSlideDuration(kSlideOutDurationMs); |
485 animation_->Hide(); | 486 animation_->Hide(); |
486 } | 487 } |
487 | 488 |
488 void FullscreenExitBubbleViews::Show() { | 489 void ExclusiveAccessBubbleViews::Show() { |
489 animation_->SetSlideDuration(kSlideInDurationMs); | 490 animation_->SetSlideDuration(kSlideInDurationMs); |
490 animation_->Show(); | 491 animation_->Show(); |
491 } | 492 } |
492 | 493 |
493 bool FullscreenExitBubbleViews::IsAnimating() { | 494 bool ExclusiveAccessBubbleViews::IsAnimating() { |
494 return animation_->is_animating(); | 495 return animation_->is_animating(); |
495 } | 496 } |
496 | 497 |
497 bool FullscreenExitBubbleViews::CanMouseTriggerSlideIn() const { | 498 bool ExclusiveAccessBubbleViews::CanMouseTriggerSlideIn() const { |
498 return !browser_view_->immersive_mode_controller()->IsEnabled(); | 499 return !browser_view_->immersive_mode_controller()->IsEnabled(); |
499 } | 500 } |
500 | 501 |
501 void FullscreenExitBubbleViews::Observe( | 502 void ExclusiveAccessBubbleViews::Observe( |
502 int type, | 503 int type, |
503 const content::NotificationSource& source, | 504 const content::NotificationSource& source, |
504 const content::NotificationDetails& details) { | 505 const content::NotificationDetails& details) { |
505 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); | 506 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); |
506 UpdateForImmersiveState(); | 507 UpdateForImmersiveState(); |
507 } | 508 } |
508 | 509 |
509 void FullscreenExitBubbleViews::OnWidgetVisibilityChanged( | 510 void ExclusiveAccessBubbleViews::OnWidgetVisibilityChanged( |
510 views::Widget* widget, | 511 views::Widget* widget, |
511 bool visible) { | 512 bool visible) { |
512 UpdateMouseWatcher(); | 513 UpdateMouseWatcher(); |
513 } | 514 } |
OLD | NEW |