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 "ui/app_list/views/app_list_view.h" | 5 #include "ui/app_list/views/app_list_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/win/windows_version.h" | 11 #include "base/win/windows_version.h" |
12 #include "ui/app_list/app_list_constants.h" | 12 #include "ui/app_list/app_list_constants.h" |
13 #include "ui/app_list/app_list_model.h" | 13 #include "ui/app_list/app_list_model.h" |
14 #include "ui/app_list/app_list_view_delegate.h" | 14 #include "ui/app_list/app_list_view_delegate.h" |
15 #include "ui/app_list/pagination_model.h" | 15 #include "ui/app_list/pagination_model.h" |
16 #include "ui/app_list/signin_delegate.h" | 16 #include "ui/app_list/signin_delegate.h" |
17 #include "ui/app_list/speech_ui_model.h" | 17 #include "ui/app_list/speech_ui_model.h" |
18 #include "ui/app_list/views/app_list_background.h" | 18 #include "ui/app_list/views/app_list_background.h" |
19 #include "ui/app_list/views/app_list_folder_view.h" | 19 #include "ui/app_list/views/app_list_folder_view.h" |
20 #include "ui/app_list/views/app_list_main_view.h" | 20 #include "ui/app_list/views/app_list_main_view.h" |
21 #include "ui/app_list/views/app_list_view_observer.h" | 21 #include "ui/app_list/views/app_list_view_observer.h" |
22 #include "ui/app_list/views/apps_container_view.h" | 22 #include "ui/app_list/views/apps_container_view.h" |
23 #include "ui/app_list/views/contents_view.h" | 23 #include "ui/app_list/views/contents_view.h" |
24 #include "ui/app_list/views/search_box_view.h" | 24 #include "ui/app_list/views/search_box_view.h" |
25 #include "ui/app_list/views/signin_view.h" | 25 #include "ui/app_list/views/signin_view.h" |
26 #include "ui/app_list/views/speech_view.h" | 26 #include "ui/app_list/views/speech_view.h" |
27 #include "ui/aura/window.h" | |
28 #include "ui/aura/window_tree_host.h" | |
27 #include "ui/base/ui_base_switches.h" | 29 #include "ui/base/ui_base_switches.h" |
28 #include "ui/compositor/layer.h" | 30 #include "ui/compositor/layer.h" |
29 #include "ui/compositor/layer_animation_observer.h" | 31 #include "ui/compositor/layer_animation_observer.h" |
30 #include "ui/compositor/scoped_layer_animation_settings.h" | 32 #include "ui/compositor/scoped_layer_animation_settings.h" |
31 #include "ui/gfx/image/image_skia.h" | 33 #include "ui/gfx/image/image_skia.h" |
32 #include "ui/gfx/insets.h" | 34 #include "ui/gfx/insets.h" |
33 #include "ui/gfx/path.h" | 35 #include "ui/gfx/path.h" |
34 #include "ui/gfx/skia_util.h" | 36 #include "ui/gfx/skia_util.h" |
35 #include "ui/views/bubble/bubble_frame_view.h" | 37 #include "ui/views/bubble/bubble_frame_view.h" |
36 #include "ui/views/bubble/bubble_window_targeter.h" | 38 #include "ui/views/bubble/bubble_window_targeter.h" |
37 #include "ui/views/controls/textfield/textfield.h" | 39 #include "ui/views/controls/textfield/textfield.h" |
38 #include "ui/views/layout/fill_layout.h" | 40 #include "ui/views/layout/fill_layout.h" |
39 #include "ui/views/widget/widget.h" | 41 #include "ui/views/widget/widget.h" |
40 | 42 |
41 #if defined(USE_AURA) | |
42 #include "ui/aura/window.h" | |
43 #include "ui/aura/window_tree_host.h" | |
44 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
45 #include "ui/base/win/shell.h" | 44 #include "ui/base/win/shell.h" |
46 #endif | 45 #endif |
46 | |
47 #if !defined(OS_CHROMEOS) | 47 #if !defined(OS_CHROMEOS) |
48 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 48 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
49 #endif | 49 #endif |
50 #endif // defined(USE_AURA) | |
51 | 50 |
52 namespace app_list { | 51 namespace app_list { |
53 | 52 |
54 namespace { | 53 namespace { |
55 | 54 |
56 void (*g_next_paint_callback)(); | 55 void (*g_next_paint_callback)(); |
57 | 56 |
58 // The margin from the edge to the speech UI. | 57 // The margin from the edge to the speech UI. |
59 const int kSpeechUIMargin = 12; | 58 const int kSpeechUIMargin = 12; |
60 | 59 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 observers_.RemoveObserver(observer); | 244 observers_.RemoveObserver(observer); |
246 } | 245 } |
247 | 246 |
248 // static | 247 // static |
249 void AppListView::SetNextPaintCallback(void (*callback)()) { | 248 void AppListView::SetNextPaintCallback(void (*callback)()) { |
250 g_next_paint_callback = callback; | 249 g_next_paint_callback = callback; |
251 } | 250 } |
252 | 251 |
253 #if defined(OS_WIN) | 252 #if defined(OS_WIN) |
254 HWND AppListView::GetHWND() const { | 253 HWND AppListView::GetHWND() const { |
255 #if defined(USE_AURA) | |
256 gfx::NativeWindow window = | 254 gfx::NativeWindow window = |
257 GetWidget()->GetTopLevelWidget()->GetNativeWindow(); | 255 GetWidget()->GetTopLevelWidget()->GetNativeWindow(); |
258 return window->GetHost()->GetAcceleratedWidget(); | 256 return window->GetHost()->GetAcceleratedWidget(); |
259 #else | |
260 return GetWidget()->GetTopLevelWidget()->GetNativeWindow(); | |
261 #endif | |
262 } | 257 } |
263 #endif | 258 #endif |
264 | 259 |
265 void AppListView::InitAsBubbleInternal(gfx::NativeView parent, | 260 void AppListView::InitAsBubbleInternal(gfx::NativeView parent, |
266 PaginationModel* pagination_model, | 261 PaginationModel* pagination_model, |
267 views::BubbleBorder::Arrow arrow, | 262 views::BubbleBorder::Arrow arrow, |
268 bool border_accepts_events, | 263 bool border_accepts_events, |
269 const gfx::Vector2d& anchor_offset) { | 264 const gfx::Vector2d& anchor_offset) { |
270 app_list_main_view_ = new AppListMainView(delegate_.get(), | 265 app_list_main_view_ = new AppListMainView(delegate_.get(), |
271 pagination_model, | 266 pagination_model, |
272 parent); | 267 parent); |
273 AddChildView(app_list_main_view_); | 268 AddChildView(app_list_main_view_); |
274 #if defined(USE_AURA) | |
275 app_list_main_view_->SetPaintToLayer(true); | 269 app_list_main_view_->SetPaintToLayer(true); |
276 app_list_main_view_->SetFillsBoundsOpaquely(false); | 270 app_list_main_view_->SetFillsBoundsOpaquely(false); |
277 app_list_main_view_->layer()->SetMasksToBounds(true); | 271 app_list_main_view_->layer()->SetMasksToBounds(true); |
278 #endif | |
279 | 272 |
280 signin_view_ = | 273 signin_view_ = |
281 new SigninView(delegate_->GetSigninDelegate(), | 274 new SigninView(delegate_->GetSigninDelegate(), |
282 app_list_main_view_->GetPreferredSize().width()); | 275 app_list_main_view_->GetPreferredSize().width()); |
283 AddChildView(signin_view_); | 276 AddChildView(signin_view_); |
284 | 277 |
285 // Speech recognition is available only when the start page exists. | 278 // Speech recognition is available only when the start page exists. |
286 if (delegate_ && delegate_->GetSpeechRecognitionContents()) { | 279 if (delegate_ && delegate_->GetSpeechRecognitionContents()) { |
287 speech_view_ = new SpeechView(delegate_.get()); | 280 speech_view_ = new SpeechView(delegate_.get()); |
288 speech_view_->SetVisible(false); | 281 speech_view_->SetVisible(false); |
289 #if defined(USE_AURA) | |
290 speech_view_->SetPaintToLayer(true); | 282 speech_view_->SetPaintToLayer(true); |
291 speech_view_->SetFillsBoundsOpaquely(false); | 283 speech_view_->SetFillsBoundsOpaquely(false); |
292 speech_view_->layer()->SetOpacity(0.0f); | 284 speech_view_->layer()->SetOpacity(0.0f); |
293 #endif | |
294 AddChildView(speech_view_); | 285 AddChildView(speech_view_); |
295 } | 286 } |
296 | 287 |
297 OnProfilesChanged(); | 288 OnProfilesChanged(); |
298 set_color(kContentsBackgroundColor); | 289 set_color(kContentsBackgroundColor); |
299 set_margins(gfx::Insets()); | 290 set_margins(gfx::Insets()); |
300 set_move_with_anchor(true); | 291 set_move_with_anchor(true); |
301 set_parent_window(parent); | 292 set_parent_window(parent); |
302 set_close_on_deactivate(false); | 293 set_close_on_deactivate(false); |
303 set_close_on_esc(false); | 294 set_close_on_esc(false); |
304 set_anchor_view_insets(gfx::Insets(kArrowOffset + anchor_offset.y(), | 295 set_anchor_view_insets(gfx::Insets(kArrowOffset + anchor_offset.y(), |
305 kArrowOffset + anchor_offset.x(), | 296 kArrowOffset + anchor_offset.x(), |
306 kArrowOffset - anchor_offset.y(), | 297 kArrowOffset - anchor_offset.y(), |
307 kArrowOffset - anchor_offset.x())); | 298 kArrowOffset - anchor_offset.x())); |
308 set_border_accepts_events(border_accepts_events); | 299 set_border_accepts_events(border_accepts_events); |
309 set_shadow(SupportsShadow() ? views::BubbleBorder::BIG_SHADOW | 300 set_shadow(SupportsShadow() ? views::BubbleBorder::BIG_SHADOW |
310 : views::BubbleBorder::NO_SHADOW_OPAQUE_BORDER); | 301 : views::BubbleBorder::NO_SHADOW_OPAQUE_BORDER); |
311 views::BubbleDelegateView::CreateBubble(this); | 302 views::BubbleDelegateView::CreateBubble(this); |
312 SetBubbleArrow(arrow); | 303 SetBubbleArrow(arrow); |
313 | 304 |
314 #if defined(USE_AURA) | |
tapted
2014/04/23 23:38:09
I think this and one below were the only USE_AURA
| |
315 aura::Window* window = GetWidget()->GetNativeWindow(); | 305 aura::Window* window = GetWidget()->GetNativeWindow(); |
316 window->layer()->SetMasksToBounds(true); | 306 window->layer()->SetMasksToBounds(true); |
317 GetBubbleFrameView()->set_background(new AppListBackground( | 307 GetBubbleFrameView()->set_background(new AppListBackground( |
318 GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius(), | 308 GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius(), |
319 app_list_main_view_)); | 309 app_list_main_view_)); |
320 set_background(NULL); | 310 set_background(NULL); |
321 window->SetEventTargeter(scoped_ptr<ui::EventTargeter>( | 311 window->SetEventTargeter(scoped_ptr<ui::EventTargeter>( |
322 new views::BubbleWindowTargeter(this))); | 312 new views::BubbleWindowTargeter(this))); |
323 #else | |
324 set_background(new AppListBackground( | |
325 GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius(), | |
326 app_list_main_view_)); | |
327 | |
328 // On non-aura the bubble has two widgets, and it's possible for the border | |
329 // to be shown independently in odd situations. Explicitly hide the bubble | |
330 // widget to ensure that any WM_WINDOWPOSCHANGED messages triggered by the | |
331 // window manager do not have the SWP_SHOWWINDOW flag set which would cause | |
332 // the border to be shown. See http://crbug.com/231687 . | |
333 GetWidget()->Hide(); | |
334 #endif | |
335 | 313 |
336 if (delegate_) | 314 if (delegate_) |
337 delegate_->ViewInitialized(); | 315 delegate_->ViewInitialized(); |
338 } | 316 } |
339 | 317 |
340 void AppListView::OnBeforeBubbleWidgetInit( | 318 void AppListView::OnBeforeBubbleWidgetInit( |
341 views::Widget::InitParams* params, | 319 views::Widget::InitParams* params, |
342 views::Widget* widget) const { | 320 views::Widget* widget) const { |
343 #if defined(USE_AURA) && !defined(OS_CHROMEOS) | 321 #if !defined(OS_CHROMEOS) |
tapted
2014/04/23 23:38:09
mac-views won't like this either :)
| |
344 if (delegate_ && delegate_->ForceNativeDesktop()) | 322 if (delegate_ && delegate_->ForceNativeDesktop()) |
345 params->native_widget = new views::DesktopNativeWidgetAura(widget); | 323 params->native_widget = new views::DesktopNativeWidgetAura(widget); |
346 #endif | 324 #endif |
347 #if defined(OS_WIN) | 325 #if defined(OS_WIN) |
348 // Windows 7 and higher offer pinning to the taskbar, but we need presence | 326 // Windows 7 and higher offer pinning to the taskbar, but we need presence |
349 // on the taskbar for the user to be able to pin us. So, show the window on | 327 // on the taskbar for the user to be able to pin us. So, show the window on |
350 // the taskbar for these versions of Windows. | 328 // the taskbar for these versions of Windows. |
351 if (base::win::GetVersion() >= base::win::VERSION_WIN7) | 329 if (base::win::GetVersion() >= base::win::VERSION_WIN7) |
352 params->force_show_in_taskbar = true; | 330 params->force_show_in_taskbar = true; |
353 #elif defined(OS_LINUX) | 331 #elif defined(OS_LINUX) |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
463 | 441 |
464 bool recognizing = (new_state == SPEECH_RECOGNITION_RECOGNIZING || | 442 bool recognizing = (new_state == SPEECH_RECOGNITION_RECOGNIZING || |
465 new_state == SPEECH_RECOGNITION_IN_SPEECH); | 443 new_state == SPEECH_RECOGNITION_IN_SPEECH); |
466 // No change for this class. | 444 // No change for this class. |
467 if (speech_view_->visible() == recognizing) | 445 if (speech_view_->visible() == recognizing) |
468 return; | 446 return; |
469 | 447 |
470 if (recognizing) | 448 if (recognizing) |
471 speech_view_->Reset(); | 449 speech_view_->Reset(); |
472 | 450 |
473 #if defined(USE_AURA) | |
474 animation_observer_->set_frame(GetBubbleFrameView()); | 451 animation_observer_->set_frame(GetBubbleFrameView()); |
475 gfx::Transform speech_transform; | 452 gfx::Transform speech_transform; |
476 speech_transform.Translate( | 453 speech_transform.Translate( |
477 0, SkFloatToMScalar(kSpeechUIAppearingPosition)); | 454 0, SkFloatToMScalar(kSpeechUIAppearingPosition)); |
478 if (recognizing) | 455 if (recognizing) |
479 speech_view_->layer()->SetTransform(speech_transform); | 456 speech_view_->layer()->SetTransform(speech_transform); |
480 | 457 |
481 { | 458 { |
482 ui::ScopedLayerAnimationSettings main_settings( | 459 ui::ScopedLayerAnimationSettings main_settings( |
483 app_list_main_view_->layer()->GetAnimator()); | 460 app_list_main_view_->layer()->GetAnimator()); |
(...skipping 16 matching lines...) Expand all Loading... | |
500 if (recognizing) | 477 if (recognizing) |
501 speech_view_->layer()->SetTransform(gfx::Transform()); | 478 speech_view_->layer()->SetTransform(gfx::Transform()); |
502 else | 479 else |
503 speech_view_->layer()->SetTransform(speech_transform); | 480 speech_view_->layer()->SetTransform(speech_transform); |
504 } | 481 } |
505 | 482 |
506 if (recognizing) | 483 if (recognizing) |
507 speech_view_->SetVisible(true); | 484 speech_view_->SetVisible(true); |
508 else | 485 else |
509 app_list_main_view_->SetVisible(true); | 486 app_list_main_view_->SetVisible(true); |
510 #else | |
511 speech_view_->SetVisible(recognizing); | |
512 app_list_main_view_->SetVisible(!recognizing); | |
513 | |
514 // Needs to schedule paint of AppListView itself, to repaint the background. | |
515 GetBubbleFrameView()->SchedulePaint(); | |
516 #endif | |
517 } | 487 } |
518 | 488 |
519 } // namespace app_list | 489 } // namespace app_list |
OLD | NEW |