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/bubble/bubble.h" | 5 #include "chrome/browser/ui/views/bubble/bubble.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "chrome/browser/ui/views/bubble/border_contents.h" | 9 #include "chrome/browser/ui/views/bubble/border_contents.h" |
10 #include "chrome/common/chrome_notification_types.h" | 10 #include "chrome/common/chrome_notification_types.h" |
11 #include "content/common/notification_service.h" | 11 #include "content/common/notification_service.h" |
12 #include "ui/base/animation/slide_animation.h" | 12 #include "ui/base/animation/slide_animation.h" |
13 #include "ui/base/keycodes/keyboard_codes.h" | 13 #include "ui/base/keycodes/keyboard_codes.h" |
14 #include "ui/gfx/color_utils.h" | 14 #include "ui/gfx/color_utils.h" |
15 #include "views/layout/fill_layout.h" | 15 #include "views/layout/fill_layout.h" |
16 #include "views/widget/widget.h" | 16 #include "views/widget/widget.h" |
17 #include "views/window/client_view.h" | 17 #include "views/window/client_view.h" |
18 | 18 |
19 #if defined(OS_CHROMEOS) | 19 #if defined(OS_CHROMEOS) |
20 #include "chrome/browser/chromeos/wm_ipc.h" | 20 #include "chrome/browser/chromeos/wm_ipc.h" |
21 #include "third_party/cros_system_api/window_manager/chromeos_wm_ipc_enums.h" | 21 #include "third_party/cros_system_api/window_manager/chromeos_wm_ipc_enums.h" |
22 #endif | 22 #endif |
23 | 23 |
24 #if defined(OS_WIN) | 24 #if defined(OS_WIN) && !defined(USE_AURA) |
25 #include "chrome/browser/ui/views/bubble/border_widget_win.h" | 25 #include "chrome/browser/ui/views/bubble/border_widget_win.h" |
26 #endif | 26 #endif |
27 | 27 |
28 using std::vector; | 28 using std::vector; |
29 | 29 |
30 // How long the fade should last for. | 30 // How long the fade should last for. |
31 static const int kHideFadeDurationMS = 200; | 31 static const int kHideFadeDurationMS = 200; |
32 | 32 |
33 // Background color of the bubble. | 33 // Background color of the bubble. |
34 #if defined(OS_WIN) | 34 #if defined(OS_WIN) && !defined(USE_AURA) |
35 const SkColor Bubble::kBackgroundColor = | 35 const SkColor Bubble::kBackgroundColor = |
36 color_utils::GetSysSkColor(COLOR_WINDOW); | 36 color_utils::GetSysSkColor(COLOR_WINDOW); |
37 #else | 37 #else |
38 // TODO(beng): source from theme provider. | 38 // TODO(beng): source from theme provider. |
39 const SkColor Bubble::kBackgroundColor = SK_ColorWHITE; | 39 const SkColor Bubble::kBackgroundColor = SK_ColorWHITE; |
40 #endif | 40 #endif |
41 | 41 |
42 // BubbleDelegate --------------------------------------------------------- | 42 // BubbleDelegate --------------------------------------------------------- |
43 | 43 |
44 std::wstring BubbleDelegate::accessible_name() { | 44 std::wstring BubbleDelegate::accessible_name() { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 FadeOut(); | 90 FadeOut(); |
91 else | 91 else |
92 DoClose(false); | 92 DoClose(false); |
93 } | 93 } |
94 | 94 |
95 void Bubble::AnimationEnded(const ui::Animation* animation) { | 95 void Bubble::AnimationEnded(const ui::Animation* animation) { |
96 if (static_cast<int>(animation_->GetCurrentValue()) == 0) { | 96 if (static_cast<int>(animation_->GetCurrentValue()) == 0) { |
97 // When fading out we just need to close the bubble at the end | 97 // When fading out we just need to close the bubble at the end |
98 DoClose(false); | 98 DoClose(false); |
99 } else { | 99 } else { |
100 #if defined(OS_WIN) | 100 #if defined(OS_WIN) && !defined(USE_AURA) |
101 // When fading in we need to remove the layered window style flag, since | 101 // When fading in we need to remove the layered window style flag, since |
102 // that style prevents some bubble content from working properly. | 102 // that style prevents some bubble content from working properly. |
103 SetWindowLong(GWL_EXSTYLE, GetWindowLong(GWL_EXSTYLE) & ~WS_EX_LAYERED); | 103 SetWindowLong(GWL_EXSTYLE, GetWindowLong(GWL_EXSTYLE) & ~WS_EX_LAYERED); |
104 #endif | 104 #endif |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 void Bubble::AnimationProgressed(const ui::Animation* animation) { | 108 void Bubble::AnimationProgressed(const ui::Animation* animation) { |
109 // Set the opacity for the main contents window. | 109 // Set the opacity for the main contents window. |
110 unsigned char opacity = static_cast<unsigned char>( | 110 unsigned char opacity = static_cast<unsigned char>( |
111 animation_->GetCurrentValue() * 255); | 111 animation_->GetCurrentValue() * 255); |
112 #if defined(OS_WIN) | 112 #if defined(USE_AURA) |
| 113 // TODO(beng): |
| 114 NOTIMPLEMENTED(); |
| 115 #elif defined(OS_WIN) |
113 SetLayeredWindowAttributes(GetNativeView(), 0, | 116 SetLayeredWindowAttributes(GetNativeView(), 0, |
114 static_cast<byte>(opacity), LWA_ALPHA); | 117 static_cast<byte>(opacity), LWA_ALPHA); |
115 contents_->SchedulePaint(); | 118 contents_->SchedulePaint(); |
116 | 119 |
117 // Also fade in/out the bubble border window. | 120 // Also fade in/out the bubble border window. |
118 border_->SetOpacity(opacity); | 121 border_->SetOpacity(opacity); |
119 border_->border_contents()->SchedulePaint(); | 122 border_->border_contents()->SchedulePaint(); |
120 #else | 123 #else |
121 SetOpacity(opacity); | 124 SetOpacity(opacity); |
122 border_contents_->SchedulePaint(); | 125 border_contents_->SchedulePaint(); |
123 #endif | 126 #endif |
124 } | 127 } |
125 | 128 |
126 Bubble::Bubble() | 129 Bubble::Bubble() |
127 : | 130 : |
128 #if defined(OS_WIN) | 131 #if defined(USE_AURA) |
| 132 views::NativeWidgetAura(new views::Widget), |
| 133 #elif defined(OS_WIN) |
129 views::NativeWidgetWin(new views::Widget), | 134 views::NativeWidgetWin(new views::Widget), |
130 #elif defined(TOOLKIT_USES_GTK) | 135 #elif defined(TOOLKIT_USES_GTK) |
131 views::NativeWidgetGtk(new views::Widget), | 136 views::NativeWidgetGtk(new views::Widget), |
132 #endif | 137 #endif |
133 #if defined(TOOLKIT_USES_GTK) | 138 #if defined(USE_AURA) |
| 139 #elif defined(TOOLKIT_USES_GTK) |
134 border_contents_(NULL), | 140 border_contents_(NULL), |
135 #elif defined(OS_WIN) | 141 #elif defined(OS_WIN) |
136 border_(NULL), | 142 border_(NULL), |
137 #endif | 143 #endif |
138 delegate_(NULL), | 144 delegate_(NULL), |
139 show_status_(kOpen), | 145 show_status_(kOpen), |
140 fade_away_on_close_(false), | 146 fade_away_on_close_(false), |
141 #if defined(TOOLKIT_USES_GTK) | 147 #if defined(TOOLKIT_USES_GTK) |
142 type_(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS), | 148 type_(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS), |
143 #endif | 149 #endif |
(...skipping 28 matching lines...) Expand all Loading... |
172 views::BubbleBorder::ArrowLocation arrow_location, | 178 views::BubbleBorder::ArrowLocation arrow_location, |
173 views::View* contents, | 179 views::View* contents, |
174 BubbleDelegate* delegate) { | 180 BubbleDelegate* delegate) { |
175 delegate_ = delegate; | 181 delegate_ = delegate; |
176 position_relative_to_ = position_relative_to; | 182 position_relative_to_ = position_relative_to; |
177 arrow_location_ = arrow_location; | 183 arrow_location_ = arrow_location; |
178 contents_ = contents; | 184 contents_ = contents; |
179 const bool fade_in = delegate_ && delegate_->FadeInOnShow(); | 185 const bool fade_in = delegate_ && delegate_->FadeInOnShow(); |
180 | 186 |
181 // Create the main window. | 187 // Create the main window. |
182 #if defined(OS_WIN) | 188 #if defined(USE_AURA) |
| 189 // TODO(beng): |
| 190 NOTIMPLEMENTED(); |
| 191 #elif defined(OS_WIN) |
183 views::Widget* parent_window = parent->GetTopLevelWidget(); | 192 views::Widget* parent_window = parent->GetTopLevelWidget(); |
184 if (parent_window) | 193 if (parent_window) |
185 parent_window->DisableInactiveRendering(); | 194 parent_window->DisableInactiveRendering(); |
186 set_window_style(WS_POPUP | WS_CLIPCHILDREN); | 195 set_window_style(WS_POPUP | WS_CLIPCHILDREN); |
187 int extended_style = WS_EX_TOOLWINDOW; | 196 int extended_style = WS_EX_TOOLWINDOW; |
188 // During FadeIn we need to turn on the layered window style to deal with | 197 // During FadeIn we need to turn on the layered window style to deal with |
189 // transparency. This flag needs to be reset after fading in is complete. | 198 // transparency. This flag needs to be reset after fading in is complete. |
190 if (fade_in) | 199 if (fade_in) |
191 extended_style |= WS_EX_LAYERED; | 200 extended_style |= WS_EX_LAYERED; |
192 set_window_ex_style(extended_style); | 201 set_window_ex_style(extended_style); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 // (e.g. calling SetChecked() on checkboxes is safe). | 246 // (e.g. calling SetChecked() on checkboxes is safe). |
238 GetWidget()->SetContentsView(contents_view); | 247 GetWidget()->SetContentsView(contents_view); |
239 // Adding |contents| as a child has to be done before we call | 248 // Adding |contents| as a child has to be done before we call |
240 // contents->GetPreferredSize() below, since some supplied views don't | 249 // contents->GetPreferredSize() below, since some supplied views don't |
241 // actually initialize themselves until they're added to a hierarchy. | 250 // actually initialize themselves until they're added to a hierarchy. |
242 contents_view->AddChildView(contents); | 251 contents_view->AddChildView(contents); |
243 | 252 |
244 // Calculate and set the bounds for all windows and views. | 253 // Calculate and set the bounds for all windows and views. |
245 gfx::Rect window_bounds; | 254 gfx::Rect window_bounds; |
246 | 255 |
247 #if defined(OS_WIN) | 256 #if defined(USE_AURA) |
| 257 // TODO(beng): |
| 258 NOTIMPLEMENTED(); |
| 259 #elif defined(OS_WIN) |
248 // Initialize and position the border window. | 260 // Initialize and position the border window. |
249 window_bounds = border_->SizeAndGetBounds(position_relative_to, | 261 window_bounds = border_->SizeAndGetBounds(position_relative_to, |
250 arrow_location, | 262 arrow_location, |
251 contents->GetPreferredSize()); | 263 contents->GetPreferredSize()); |
252 | 264 |
253 // Make |contents| take up the entire contents view. | 265 // Make |contents| take up the entire contents view. |
254 contents_view->SetLayoutManager(new views::FillLayout); | 266 contents_view->SetLayoutManager(new views::FillLayout); |
255 | 267 |
256 // Paint the background color behind the contents. | 268 // Paint the background color behind the contents. |
257 contents_view->set_background( | 269 contents_view->set_background( |
(...skipping 12 matching lines...) Expand all Loading... |
270 | 282 |
271 // |contents_view| has no layout manager, so we have to explicitly position | 283 // |contents_view| has no layout manager, so we have to explicitly position |
272 // its children. | 284 // its children. |
273 border_contents_->SetBoundsRect( | 285 border_contents_->SetBoundsRect( |
274 gfx::Rect(gfx::Point(), window_bounds.size())); | 286 gfx::Rect(gfx::Point(), window_bounds.size())); |
275 contents->SetBoundsRect(contents_bounds); | 287 contents->SetBoundsRect(contents_bounds); |
276 #endif | 288 #endif |
277 GetWidget()->SetBounds(window_bounds); | 289 GetWidget()->SetBounds(window_bounds); |
278 | 290 |
279 // Show the window. | 291 // Show the window. |
280 #if defined(OS_WIN) | 292 #if defined(USE_AURA) |
| 293 // TODO(beng): |
| 294 NOTIMPLEMENTED(); |
| 295 #elif defined(OS_WIN) |
281 border_->ShowWindow(SW_SHOW); | 296 border_->ShowWindow(SW_SHOW); |
282 ShowWindow(SW_SHOW); | 297 ShowWindow(SW_SHOW); |
283 #elif defined(TOOLKIT_USES_GTK) | 298 #elif defined(TOOLKIT_USES_GTK) |
284 GetWidget()->Show(); | 299 GetWidget()->Show(); |
285 #endif | 300 #endif |
286 | 301 |
287 if (fade_in) | 302 if (fade_in) |
288 FadeIn(); | 303 FadeIn(); |
289 } | 304 } |
290 | 305 |
(...skipping 10 matching lines...) Expand all Loading... |
301 accelerator_registered_ = false; | 316 accelerator_registered_ = false; |
302 } | 317 } |
303 | 318 |
304 BorderContents* Bubble::CreateBorderContents() { | 319 BorderContents* Bubble::CreateBorderContents() { |
305 return new BorderContents(); | 320 return new BorderContents(); |
306 } | 321 } |
307 | 322 |
308 void Bubble::SizeToContents() { | 323 void Bubble::SizeToContents() { |
309 gfx::Rect window_bounds; | 324 gfx::Rect window_bounds; |
310 | 325 |
311 #if defined(OS_WIN) | 326 #if defined(USE_AURA) |
| 327 // TODO(beng): |
| 328 NOTIMPLEMENTED(); |
| 329 #elif defined(OS_WIN) |
312 // Initialize and position the border window. | 330 // Initialize and position the border window. |
313 window_bounds = border_->SizeAndGetBounds(position_relative_to_, | 331 window_bounds = border_->SizeAndGetBounds(position_relative_to_, |
314 arrow_location_, | 332 arrow_location_, |
315 contents_->GetPreferredSize()); | 333 contents_->GetPreferredSize()); |
316 #else | 334 #else |
317 gfx::Rect contents_bounds; | 335 gfx::Rect contents_bounds; |
318 border_contents_->SizeAndGetBounds(position_relative_to_, | 336 border_contents_->SizeAndGetBounds(position_relative_to_, |
319 arrow_location_, false, contents_->GetPreferredSize(), | 337 arrow_location_, false, contents_->GetPreferredSize(), |
320 &contents_bounds, &window_bounds); | 338 &contents_bounds, &window_bounds); |
321 // |contents_view| has no layout manager, so we have to explicitly position | 339 // |contents_view| has no layout manager, so we have to explicitly position |
322 // its children. | 340 // its children. |
323 border_contents_->SetBoundsRect( | 341 border_contents_->SetBoundsRect( |
324 gfx::Rect(gfx::Point(), window_bounds.size())); | 342 gfx::Rect(gfx::Point(), window_bounds.size())); |
325 contents_->SetBoundsRect(contents_bounds); | 343 contents_->SetBoundsRect(contents_bounds); |
326 #endif | 344 #endif |
327 GetWidget()->SetBounds(window_bounds); | 345 GetWidget()->SetBounds(window_bounds); |
328 } | 346 } |
329 | 347 |
330 #if defined(OS_WIN) | 348 #if defined(USE_AURA) |
| 349 // TODO(beng): |
| 350 #elif defined(OS_WIN) |
331 void Bubble::OnActivate(UINT action, BOOL minimized, HWND window) { | 351 void Bubble::OnActivate(UINT action, BOOL minimized, HWND window) { |
332 // The popup should close when it is deactivated. | 352 // The popup should close when it is deactivated. |
333 if (action == WA_INACTIVE) { | 353 if (action == WA_INACTIVE) { |
334 GetWidget()->Close(); | 354 GetWidget()->Close(); |
335 } else if (action == WA_ACTIVE) { | 355 } else if (action == WA_ACTIVE) { |
336 DCHECK(GetWidget()->GetRootView()->has_children()); | 356 DCHECK(GetWidget()->GetRootView()->has_children()); |
337 GetWidget()->GetRootView()->child_at(0)->RequestFocus(); | 357 GetWidget()->GetRootView()->child_at(0)->RequestFocus(); |
338 } | 358 } |
339 } | 359 } |
340 #elif defined(TOOLKIT_USES_GTK) | 360 #elif defined(TOOLKIT_USES_GTK) |
341 void Bubble::OnActiveChanged() { | 361 void Bubble::OnActiveChanged() { |
342 if (!GetWidget()->IsActive()) | 362 if (!GetWidget()->IsActive()) |
343 GetWidget()->Close(); | 363 GetWidget()->Close(); |
344 } | 364 } |
345 #endif | 365 #endif |
346 | 366 |
347 void Bubble::DoClose(bool closed_by_escape) { | 367 void Bubble::DoClose(bool closed_by_escape) { |
348 if (show_status_ == kClosed) | 368 if (show_status_ == kClosed) |
349 return; | 369 return; |
350 | 370 |
351 if (accelerator_registered_) | 371 if (accelerator_registered_) |
352 UnregisterEscapeAccelerator(); | 372 UnregisterEscapeAccelerator(); |
353 if (delegate_) | 373 if (delegate_) |
354 delegate_->BubbleClosing(this, closed_by_escape); | 374 delegate_->BubbleClosing(this, closed_by_escape); |
355 show_status_ = kClosed; | 375 show_status_ = kClosed; |
356 #if defined(OS_WIN) | 376 #if defined(USE_AURA) |
| 377 // TODO(beng): |
| 378 NOTIMPLEMENTED(); |
| 379 #elif defined(OS_WIN) |
357 border_->Close(); | 380 border_->Close(); |
358 #endif | 381 #endif |
359 #if defined(OS_WIN) | 382 #if defined(USE_AURA) |
| 383 // TODO(beng): |
| 384 NOTIMPLEMENTED(); |
| 385 #elif defined(OS_WIN) |
360 NativeWidgetWin::Close(); | 386 NativeWidgetWin::Close(); |
361 #elif defined(TOOLKIT_USES_GTK) | 387 #elif defined(TOOLKIT_USES_GTK) |
362 NativeWidgetGtk::Close(); | 388 NativeWidgetGtk::Close(); |
363 #endif | 389 #endif |
364 } | 390 } |
365 | 391 |
366 void Bubble::FadeIn() { | 392 void Bubble::FadeIn() { |
367 Fade(true); // |fade_in|. | 393 Fade(true); // |fade_in|. |
368 } | 394 } |
369 | 395 |
370 void Bubble::FadeOut() { | 396 void Bubble::FadeOut() { |
371 #if defined(OS_WIN) | 397 #if defined(OS_WIN) && !defined(USE_AURA) |
372 // The contents window cannot have the layered flag on by default, since its | 398 // The contents window cannot have the layered flag on by default, since its |
373 // content doesn't always work inside a layered window, but when animating it | 399 // content doesn't always work inside a layered window, but when animating it |
374 // is ok to set that style on the window for the purpose of fading it out. | 400 // is ok to set that style on the window for the purpose of fading it out. |
375 SetWindowLong(GWL_EXSTYLE, GetWindowLong(GWL_EXSTYLE) | WS_EX_LAYERED); | 401 SetWindowLong(GWL_EXSTYLE, GetWindowLong(GWL_EXSTYLE) | WS_EX_LAYERED); |
376 // This must be the very next call, otherwise we can get flicker on close. | 402 // This must be the very next call, otherwise we can get flicker on close. |
377 SetLayeredWindowAttributes(GetNativeView(), 0, | 403 SetLayeredWindowAttributes(GetNativeView(), 0, |
378 static_cast<byte>(255), LWA_ALPHA); | 404 static_cast<byte>(255), LWA_ALPHA); |
| 405 #elif defined(USE_AURA) |
| 406 NOTIMPLEMENTED(); |
379 #endif | 407 #endif |
380 | 408 |
381 Fade(false); // |fade_in|. | 409 Fade(false); // |fade_in|. |
382 } | 410 } |
383 | 411 |
384 void Bubble::Fade(bool fade_in) { | 412 void Bubble::Fade(bool fade_in) { |
385 animation_.reset(new ui::SlideAnimation(this)); | 413 animation_.reset(new ui::SlideAnimation(this)); |
386 animation_->SetSlideDuration(kHideFadeDurationMS); | 414 animation_->SetSlideDuration(kHideFadeDurationMS); |
387 animation_->SetTweenType(ui::Tween::LINEAR); | 415 animation_->SetTweenType(ui::Tween::LINEAR); |
388 | 416 |
389 animation_->Reset(fade_in ? 0.0 : 1.0); | 417 animation_->Reset(fade_in ? 0.0 : 1.0); |
390 if (fade_in) | 418 if (fade_in) |
391 animation_->Show(); | 419 animation_->Show(); |
392 else | 420 else |
393 animation_->Hide(); | 421 animation_->Hide(); |
394 } | 422 } |
395 | 423 |
396 bool Bubble::AcceleratorPressed(const views::Accelerator& accelerator) { | 424 bool Bubble::AcceleratorPressed(const views::Accelerator& accelerator) { |
397 if (!delegate_ || delegate_->CloseOnEscape()) { | 425 if (!delegate_ || delegate_->CloseOnEscape()) { |
398 DoClose(true); | 426 DoClose(true); |
399 return true; | 427 return true; |
400 } | 428 } |
401 return false; | 429 return false; |
402 } | 430 } |
OLD | NEW |