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 #elif defined(OS_WIN) | |
sky
2011/09/06 17:22:48
NOTIMPLEMENTED?
| |
113 SetLayeredWindowAttributes(GetNativeView(), 0, | 114 SetLayeredWindowAttributes(GetNativeView(), 0, |
114 static_cast<byte>(opacity), LWA_ALPHA); | 115 static_cast<byte>(opacity), LWA_ALPHA); |
115 contents_->SchedulePaint(); | 116 contents_->SchedulePaint(); |
116 | 117 |
117 // Also fade in/out the bubble border window. | 118 // Also fade in/out the bubble border window. |
118 border_->SetOpacity(opacity); | 119 border_->SetOpacity(opacity); |
119 border_->border_contents()->SchedulePaint(); | 120 border_->border_contents()->SchedulePaint(); |
120 #else | 121 #else |
121 SetOpacity(opacity); | 122 SetOpacity(opacity); |
122 border_contents_->SchedulePaint(); | 123 border_contents_->SchedulePaint(); |
123 #endif | 124 #endif |
124 } | 125 } |
125 | 126 |
126 Bubble::Bubble() | 127 Bubble::Bubble() |
127 : | 128 : |
128 #if defined(OS_WIN) | 129 #if defined(USE_AURA) |
130 views::NativeWidgetAura(new views::Widget), | |
131 #elif defined(OS_WIN) | |
129 views::NativeWidgetWin(new views::Widget), | 132 views::NativeWidgetWin(new views::Widget), |
130 #elif defined(TOOLKIT_USES_GTK) | 133 #elif defined(TOOLKIT_USES_GTK) |
131 views::NativeWidgetGtk(new views::Widget), | 134 views::NativeWidgetGtk(new views::Widget), |
132 #endif | 135 #endif |
133 #if defined(TOOLKIT_USES_GTK) | 136 #if defined(USE_AURA) |
137 #elif defined(TOOLKIT_USES_GTK) | |
134 border_contents_(NULL), | 138 border_contents_(NULL), |
135 #elif defined(OS_WIN) | 139 #elif defined(OS_WIN) |
136 border_(NULL), | 140 border_(NULL), |
137 #endif | 141 #endif |
138 delegate_(NULL), | 142 delegate_(NULL), |
139 show_status_(kOpen), | 143 show_status_(kOpen), |
140 fade_away_on_close_(false), | 144 fade_away_on_close_(false), |
141 #if defined(TOOLKIT_USES_GTK) | 145 #if defined(TOOLKIT_USES_GTK) |
142 type_(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS), | 146 type_(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS), |
143 #endif | 147 #endif |
(...skipping 28 matching lines...) Expand all Loading... | |
172 views::BubbleBorder::ArrowLocation arrow_location, | 176 views::BubbleBorder::ArrowLocation arrow_location, |
173 views::View* contents, | 177 views::View* contents, |
174 BubbleDelegate* delegate) { | 178 BubbleDelegate* delegate) { |
175 delegate_ = delegate; | 179 delegate_ = delegate; |
176 position_relative_to_ = position_relative_to; | 180 position_relative_to_ = position_relative_to; |
177 arrow_location_ = arrow_location; | 181 arrow_location_ = arrow_location; |
178 contents_ = contents; | 182 contents_ = contents; |
179 const bool fade_in = delegate_ && delegate_->FadeInOnShow(); | 183 const bool fade_in = delegate_ && delegate_->FadeInOnShow(); |
180 | 184 |
181 // Create the main window. | 185 // Create the main window. |
182 #if defined(OS_WIN) | 186 #if defined(USE_AURA) |
187 // TODO(beng): | |
188 NOTIMPLEMENTED(); | |
189 #elif defined(OS_WIN) | |
183 views::Widget* parent_window = parent->GetTopLevelWidget(); | 190 views::Widget* parent_window = parent->GetTopLevelWidget(); |
184 if (parent_window) | 191 if (parent_window) |
185 parent_window->DisableInactiveRendering(); | 192 parent_window->DisableInactiveRendering(); |
186 set_window_style(WS_POPUP | WS_CLIPCHILDREN); | 193 set_window_style(WS_POPUP | WS_CLIPCHILDREN); |
187 int extended_style = WS_EX_TOOLWINDOW; | 194 int extended_style = WS_EX_TOOLWINDOW; |
188 // During FadeIn we need to turn on the layered window style to deal with | 195 // 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. | 196 // transparency. This flag needs to be reset after fading in is complete. |
190 if (fade_in) | 197 if (fade_in) |
191 extended_style |= WS_EX_LAYERED; | 198 extended_style |= WS_EX_LAYERED; |
192 set_window_ex_style(extended_style); | 199 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). | 244 // (e.g. calling SetChecked() on checkboxes is safe). |
238 GetWidget()->SetContentsView(contents_view); | 245 GetWidget()->SetContentsView(contents_view); |
239 // Adding |contents| as a child has to be done before we call | 246 // Adding |contents| as a child has to be done before we call |
240 // contents->GetPreferredSize() below, since some supplied views don't | 247 // contents->GetPreferredSize() below, since some supplied views don't |
241 // actually initialize themselves until they're added to a hierarchy. | 248 // actually initialize themselves until they're added to a hierarchy. |
242 contents_view->AddChildView(contents); | 249 contents_view->AddChildView(contents); |
243 | 250 |
244 // Calculate and set the bounds for all windows and views. | 251 // Calculate and set the bounds for all windows and views. |
245 gfx::Rect window_bounds; | 252 gfx::Rect window_bounds; |
246 | 253 |
247 #if defined(OS_WIN) | 254 #if defined(USE_AURA) |
255 // TODO(beng): | |
256 NOTIMPLEMENTED(); | |
257 #elif defined(OS_WIN) | |
248 // Initialize and position the border window. | 258 // Initialize and position the border window. |
249 window_bounds = border_->SizeAndGetBounds(position_relative_to, | 259 window_bounds = border_->SizeAndGetBounds(position_relative_to, |
250 arrow_location, | 260 arrow_location, |
251 contents->GetPreferredSize()); | 261 contents->GetPreferredSize()); |
252 | 262 |
253 // Make |contents| take up the entire contents view. | 263 // Make |contents| take up the entire contents view. |
254 contents_view->SetLayoutManager(new views::FillLayout); | 264 contents_view->SetLayoutManager(new views::FillLayout); |
255 | 265 |
256 // Paint the background color behind the contents. | 266 // Paint the background color behind the contents. |
257 contents_view->set_background( | 267 contents_view->set_background( |
(...skipping 12 matching lines...) Expand all Loading... | |
270 | 280 |
271 // |contents_view| has no layout manager, so we have to explicitly position | 281 // |contents_view| has no layout manager, so we have to explicitly position |
272 // its children. | 282 // its children. |
273 border_contents_->SetBoundsRect( | 283 border_contents_->SetBoundsRect( |
274 gfx::Rect(gfx::Point(), window_bounds.size())); | 284 gfx::Rect(gfx::Point(), window_bounds.size())); |
275 contents->SetBoundsRect(contents_bounds); | 285 contents->SetBoundsRect(contents_bounds); |
276 #endif | 286 #endif |
277 GetWidget()->SetBounds(window_bounds); | 287 GetWidget()->SetBounds(window_bounds); |
278 | 288 |
279 // Show the window. | 289 // Show the window. |
280 #if defined(OS_WIN) | 290 #if defined(USE_AURA) |
291 // TODO(beng): | |
292 NOTIMPLEMENTED(); | |
293 #elif defined(OS_WIN) | |
281 border_->ShowWindow(SW_SHOW); | 294 border_->ShowWindow(SW_SHOW); |
282 ShowWindow(SW_SHOW); | 295 ShowWindow(SW_SHOW); |
283 #elif defined(TOOLKIT_USES_GTK) | 296 #elif defined(TOOLKIT_USES_GTK) |
284 GetWidget()->Show(); | 297 GetWidget()->Show(); |
285 #endif | 298 #endif |
286 | 299 |
287 if (fade_in) | 300 if (fade_in) |
288 FadeIn(); | 301 FadeIn(); |
289 } | 302 } |
290 | 303 |
(...skipping 10 matching lines...) Expand all Loading... | |
301 accelerator_registered_ = false; | 314 accelerator_registered_ = false; |
302 } | 315 } |
303 | 316 |
304 BorderContents* Bubble::CreateBorderContents() { | 317 BorderContents* Bubble::CreateBorderContents() { |
305 return new BorderContents(); | 318 return new BorderContents(); |
306 } | 319 } |
307 | 320 |
308 void Bubble::SizeToContents() { | 321 void Bubble::SizeToContents() { |
309 gfx::Rect window_bounds; | 322 gfx::Rect window_bounds; |
310 | 323 |
311 #if defined(OS_WIN) | 324 #if defined(USE_AURA) |
325 // TODO(beng): | |
326 NOTIMPLEMENTED(); | |
327 #elif defined(OS_WIN) | |
312 // Initialize and position the border window. | 328 // Initialize and position the border window. |
313 window_bounds = border_->SizeAndGetBounds(position_relative_to_, | 329 window_bounds = border_->SizeAndGetBounds(position_relative_to_, |
314 arrow_location_, | 330 arrow_location_, |
315 contents_->GetPreferredSize()); | 331 contents_->GetPreferredSize()); |
316 #else | 332 #else |
317 gfx::Rect contents_bounds; | 333 gfx::Rect contents_bounds; |
318 border_contents_->SizeAndGetBounds(position_relative_to_, | 334 border_contents_->SizeAndGetBounds(position_relative_to_, |
319 arrow_location_, false, contents_->GetPreferredSize(), | 335 arrow_location_, false, contents_->GetPreferredSize(), |
320 &contents_bounds, &window_bounds); | 336 &contents_bounds, &window_bounds); |
321 // |contents_view| has no layout manager, so we have to explicitly position | 337 // |contents_view| has no layout manager, so we have to explicitly position |
322 // its children. | 338 // its children. |
323 border_contents_->SetBoundsRect( | 339 border_contents_->SetBoundsRect( |
324 gfx::Rect(gfx::Point(), window_bounds.size())); | 340 gfx::Rect(gfx::Point(), window_bounds.size())); |
325 contents_->SetBoundsRect(contents_bounds); | 341 contents_->SetBoundsRect(contents_bounds); |
326 #endif | 342 #endif |
327 GetWidget()->SetBounds(window_bounds); | 343 GetWidget()->SetBounds(window_bounds); |
328 } | 344 } |
329 | 345 |
330 #if defined(OS_WIN) | 346 #if defined(USE_AURA) |
347 // TODO(beng): | |
348 #elif defined(OS_WIN) | |
331 void Bubble::OnActivate(UINT action, BOOL minimized, HWND window) { | 349 void Bubble::OnActivate(UINT action, BOOL minimized, HWND window) { |
332 // The popup should close when it is deactivated. | 350 // The popup should close when it is deactivated. |
333 if (action == WA_INACTIVE) { | 351 if (action == WA_INACTIVE) { |
334 GetWidget()->Close(); | 352 GetWidget()->Close(); |
335 } else if (action == WA_ACTIVE) { | 353 } else if (action == WA_ACTIVE) { |
336 DCHECK(GetWidget()->GetRootView()->has_children()); | 354 DCHECK(GetWidget()->GetRootView()->has_children()); |
337 GetWidget()->GetRootView()->child_at(0)->RequestFocus(); | 355 GetWidget()->GetRootView()->child_at(0)->RequestFocus(); |
338 } | 356 } |
339 } | 357 } |
340 #elif defined(TOOLKIT_USES_GTK) | 358 #elif defined(TOOLKIT_USES_GTK) |
341 void Bubble::OnActiveChanged() { | 359 void Bubble::OnActiveChanged() { |
342 if (!GetWidget()->IsActive()) | 360 if (!GetWidget()->IsActive()) |
343 GetWidget()->Close(); | 361 GetWidget()->Close(); |
344 } | 362 } |
345 #endif | 363 #endif |
346 | 364 |
347 void Bubble::DoClose(bool closed_by_escape) { | 365 void Bubble::DoClose(bool closed_by_escape) { |
348 if (show_status_ == kClosed) | 366 if (show_status_ == kClosed) |
349 return; | 367 return; |
350 | 368 |
351 if (accelerator_registered_) | 369 if (accelerator_registered_) |
352 UnregisterEscapeAccelerator(); | 370 UnregisterEscapeAccelerator(); |
353 if (delegate_) | 371 if (delegate_) |
354 delegate_->BubbleClosing(this, closed_by_escape); | 372 delegate_->BubbleClosing(this, closed_by_escape); |
355 show_status_ = kClosed; | 373 show_status_ = kClosed; |
356 #if defined(OS_WIN) | 374 #if defined(USE_AURA) |
375 // TODO(beng): | |
376 NOTIMPLEMENTED(); | |
377 #elif defined(OS_WIN) | |
357 border_->Close(); | 378 border_->Close(); |
358 #endif | 379 #endif |
359 #if defined(OS_WIN) | 380 #if defined(USE_AURA) |
381 // TODO(beng): | |
382 NOTIMPLEMENTED(); | |
383 #elif defined(OS_WIN) | |
360 NativeWidgetWin::Close(); | 384 NativeWidgetWin::Close(); |
361 #elif defined(TOOLKIT_USES_GTK) | 385 #elif defined(TOOLKIT_USES_GTK) |
362 NativeWidgetGtk::Close(); | 386 NativeWidgetGtk::Close(); |
363 #endif | 387 #endif |
364 } | 388 } |
365 | 389 |
366 void Bubble::FadeIn() { | 390 void Bubble::FadeIn() { |
367 Fade(true); // |fade_in|. | 391 Fade(true); // |fade_in|. |
368 } | 392 } |
369 | 393 |
370 void Bubble::FadeOut() { | 394 void Bubble::FadeOut() { |
371 #if defined(OS_WIN) | 395 #if defined(OS_WIN) && !defined(USE_AURA) |
372 // The contents window cannot have the layered flag on by default, since its | 396 // 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 | 397 // 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. | 398 // 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); | 399 SetWindowLong(GWL_EXSTYLE, GetWindowLong(GWL_EXSTYLE) | WS_EX_LAYERED); |
376 // This must be the very next call, otherwise we can get flicker on close. | 400 // This must be the very next call, otherwise we can get flicker on close. |
377 SetLayeredWindowAttributes(GetNativeView(), 0, | 401 SetLayeredWindowAttributes(GetNativeView(), 0, |
378 static_cast<byte>(255), LWA_ALPHA); | 402 static_cast<byte>(255), LWA_ALPHA); |
379 #endif | 403 #endif |
sky
2011/09/06 17:22:48
#else NOTIMPLEMNETED?
| |
380 | 404 |
381 Fade(false); // |fade_in|. | 405 Fade(false); // |fade_in|. |
382 } | 406 } |
383 | 407 |
384 void Bubble::Fade(bool fade_in) { | 408 void Bubble::Fade(bool fade_in) { |
385 animation_.reset(new ui::SlideAnimation(this)); | 409 animation_.reset(new ui::SlideAnimation(this)); |
386 animation_->SetSlideDuration(kHideFadeDurationMS); | 410 animation_->SetSlideDuration(kHideFadeDurationMS); |
387 animation_->SetTweenType(ui::Tween::LINEAR); | 411 animation_->SetTweenType(ui::Tween::LINEAR); |
388 | 412 |
389 animation_->Reset(fade_in ? 0.0 : 1.0); | 413 animation_->Reset(fade_in ? 0.0 : 1.0); |
390 if (fade_in) | 414 if (fade_in) |
391 animation_->Show(); | 415 animation_->Show(); |
392 else | 416 else |
393 animation_->Hide(); | 417 animation_->Hide(); |
394 } | 418 } |
395 | 419 |
396 bool Bubble::AcceleratorPressed(const views::Accelerator& accelerator) { | 420 bool Bubble::AcceleratorPressed(const views::Accelerator& accelerator) { |
397 if (!delegate_ || delegate_->CloseOnEscape()) { | 421 if (!delegate_ || delegate_->CloseOnEscape()) { |
398 DoClose(true); | 422 DoClose(true); |
399 return true; | 423 return true; |
400 } | 424 } |
401 return false; | 425 return false; |
402 } | 426 } |
OLD | NEW |