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/speech_ui_model.h" | 15 #include "ui/app_list/speech_ui_model.h" |
16 #include "ui/app_list/views/app_list_background.h" | 16 #include "ui/app_list/views/app_list_background.h" |
17 #include "ui/app_list/views/app_list_folder_view.h" | 17 #include "ui/app_list/views/app_list_folder_view.h" |
18 #include "ui/app_list/views/app_list_main_view.h" | 18 #include "ui/app_list/views/app_list_main_view.h" |
19 #include "ui/app_list/views/app_list_view_observer.h" | 19 #include "ui/app_list/views/app_list_view_observer.h" |
20 #include "ui/app_list/views/apps_container_view.h" | 20 #include "ui/app_list/views/apps_container_view.h" |
21 #include "ui/app_list/views/contents_view.h" | 21 #include "ui/app_list/views/contents_view.h" |
22 #include "ui/app_list/views/search_box_view.h" | 22 #include "ui/app_list/views/search_box_view.h" |
23 #include "ui/app_list/views/speech_view.h" | 23 #include "ui/app_list/views/speech_view.h" |
24 #include "ui/base/ui_base_switches.h" | 24 #include "ui/base/ui_base_switches.h" |
25 #include "ui/compositor/layer.h" | 25 #include "ui/compositor/layer.h" |
26 #include "ui/compositor/layer_animation_observer.h" | 26 #include "ui/compositor/layer_animation_observer.h" |
27 #include "ui/compositor/scoped_layer_animation_settings.h" | 27 #include "ui/compositor/scoped_layer_animation_settings.h" |
28 #include "ui/gfx/canvas.h" | |
29 #include "ui/gfx/image/image_skia.h" | 28 #include "ui/gfx/image/image_skia.h" |
30 #include "ui/gfx/insets.h" | 29 #include "ui/gfx/insets.h" |
31 #include "ui/gfx/path.h" | 30 #include "ui/gfx/path.h" |
32 #include "ui/gfx/skia_util.h" | 31 #include "ui/gfx/skia_util.h" |
33 #include "ui/views/bubble/bubble_frame_view.h" | 32 #include "ui/views/bubble/bubble_frame_view.h" |
34 #include "ui/views/controls/textfield/textfield.h" | 33 #include "ui/views/controls/textfield/textfield.h" |
35 #include "ui/views/layout/fill_layout.h" | 34 #include "ui/views/layout/fill_layout.h" |
36 #include "ui/views/widget/widget.h" | 35 #include "ui/views/widget/widget.h" |
37 | 36 |
38 #if defined(USE_AURA) | 37 #if defined(USE_AURA) |
(...skipping 30 matching lines...) Expand all Loading... |
69 switches::kDisableDwmComposition)) { | 68 switches::kDisableDwmComposition)) { |
70 return false; | 69 return false; |
71 } | 70 } |
72 #elif defined(OS_LINUX) && !defined(OS_CHROMEOS) | 71 #elif defined(OS_LINUX) && !defined(OS_CHROMEOS) |
73 // Shadows are not supported on (non-ChromeOS) Linux. | 72 // Shadows are not supported on (non-ChromeOS) Linux. |
74 return false; | 73 return false; |
75 #endif | 74 #endif |
76 return true; | 75 return true; |
77 } | 76 } |
78 | 77 |
79 // The background for the App List overlay, which appears as a white rounded | |
80 // rectangle with the given radius and the same size as the target view. | |
81 class AppListOverlayBackground : public views::Background { | |
82 public: | |
83 AppListOverlayBackground(int corner_radius) | |
84 : corner_radius_(corner_radius) {}; | |
85 virtual ~AppListOverlayBackground() {}; | |
86 | |
87 // Overridden from views::Background: | |
88 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { | |
89 SkPaint paint; | |
90 paint.setStyle(SkPaint::kFill_Style); | |
91 paint.setColor(SK_ColorWHITE); | |
92 canvas->DrawRoundRect(view->GetContentsBounds(), corner_radius_, paint); | |
93 } | |
94 | |
95 private: | |
96 const int corner_radius_; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(AppListOverlayBackground); | |
99 }; | |
100 | |
101 } // namespace | 78 } // namespace |
102 | 79 |
103 // An animation observer to hide the view at the end of the animation. | 80 // An animation observer to hide the view at the end of the animation. |
104 class HideViewAnimationObserver : public ui::ImplicitAnimationObserver { | 81 class HideViewAnimationObserver : public ui::ImplicitAnimationObserver { |
105 public: | 82 public: |
106 HideViewAnimationObserver() | 83 HideViewAnimationObserver() |
107 : frame_(NULL), | 84 : frame_(NULL), |
108 target_(NULL) { | 85 target_(NULL) { |
109 } | 86 } |
110 | 87 |
(...skipping 28 matching lines...) Expand all Loading... |
139 DISALLOW_COPY_AND_ASSIGN(HideViewAnimationObserver); | 116 DISALLOW_COPY_AND_ASSIGN(HideViewAnimationObserver); |
140 }; | 117 }; |
141 | 118 |
142 //////////////////////////////////////////////////////////////////////////////// | 119 //////////////////////////////////////////////////////////////////////////////// |
143 // AppListView: | 120 // AppListView: |
144 | 121 |
145 AppListView::AppListView(AppListViewDelegate* delegate) | 122 AppListView::AppListView(AppListViewDelegate* delegate) |
146 : delegate_(delegate), | 123 : delegate_(delegate), |
147 app_list_main_view_(NULL), | 124 app_list_main_view_(NULL), |
148 speech_view_(NULL), | 125 speech_view_(NULL), |
149 overlay_view_(NULL), | |
150 animation_observer_(new HideViewAnimationObserver()) { | 126 animation_observer_(new HideViewAnimationObserver()) { |
151 CHECK(delegate); | 127 CHECK(delegate); |
152 | 128 |
153 delegate_->AddObserver(this); | 129 delegate_->AddObserver(this); |
154 delegate_->GetSpeechUI()->AddObserver(this); | 130 delegate_->GetSpeechUI()->AddObserver(this); |
155 } | 131 } |
156 | 132 |
157 AppListView::~AppListView() { | 133 AppListView::~AppListView() { |
158 delegate_->GetSpeechUI()->RemoveObserver(this); | 134 delegate_->GetSpeechUI()->RemoveObserver(this); |
159 delegate_->RemoveObserver(this); | 135 delegate_->RemoveObserver(this); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 183 |
208 void AppListView::Close() { | 184 void AppListView::Close() { |
209 app_list_main_view_->Close(); | 185 app_list_main_view_->Close(); |
210 delegate_->Dismiss(); | 186 delegate_->Dismiss(); |
211 } | 187 } |
212 | 188 |
213 void AppListView::UpdateBounds() { | 189 void AppListView::UpdateBounds() { |
214 SizeToContents(); | 190 SizeToContents(); |
215 } | 191 } |
216 | 192 |
217 void AppListView::SetAppListOverlayVisible(bool visible) { | |
218 DCHECK(overlay_view_); | |
219 overlay_view_->SetVisible(visible); | |
220 } | |
221 | |
222 bool AppListView::ShouldCenterWindow() const { | 193 bool AppListView::ShouldCenterWindow() const { |
223 return delegate_->ShouldCenterWindow(); | 194 return delegate_->ShouldCenterWindow(); |
224 } | 195 } |
225 | 196 |
226 gfx::Size AppListView::GetPreferredSize() const { | 197 gfx::Size AppListView::GetPreferredSize() const { |
227 return app_list_main_view_->GetPreferredSize(); | 198 return app_list_main_view_->GetPreferredSize(); |
228 } | 199 } |
229 | 200 |
230 void AppListView::Paint(gfx::Canvas* canvas, const views::CullSet& cull_set) { | 201 void AppListView::Paint(gfx::Canvas* canvas, const views::CullSet& cull_set) { |
231 views::BubbleDelegateView::Paint(canvas, cull_set); | 202 views::BubbleDelegateView::Paint(canvas, cull_set); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 app_list_main_view_)); | 310 app_list_main_view_)); |
340 | 311 |
341 // On non-aura the bubble has two widgets, and it's possible for the border | 312 // On non-aura the bubble has two widgets, and it's possible for the border |
342 // to be shown independently in odd situations. Explicitly hide the bubble | 313 // to be shown independently in odd situations. Explicitly hide the bubble |
343 // widget to ensure that any WM_WINDOWPOSCHANGED messages triggered by the | 314 // widget to ensure that any WM_WINDOWPOSCHANGED messages triggered by the |
344 // window manager do not have the SWP_SHOWWINDOW flag set which would cause | 315 // window manager do not have the SWP_SHOWWINDOW flag set which would cause |
345 // the border to be shown. See http://crbug.com/231687 . | 316 // the border to be shown. See http://crbug.com/231687 . |
346 GetWidget()->Hide(); | 317 GetWidget()->Hide(); |
347 #endif | 318 #endif |
348 | 319 |
349 // To make the overlay view, construct a view with a white background, rather | |
350 // than a white rectangle in it. This is because we need overlay_view_ to be | |
351 // drawn to its own layer (so it appears correctly in the foreground). | |
352 const float kOverlayOpacity = 0.75f; | |
353 overlay_view_ = new views::View(); | |
354 overlay_view_->SetPaintToLayer(true); | |
355 overlay_view_->layer()->SetOpacity(kOverlayOpacity); | |
356 overlay_view_->SetBoundsRect(GetContentsBounds()); | |
357 overlay_view_->SetVisible(false); | |
358 | |
359 // On platforms that don't support a shadow, the rounded border of the app | |
360 // list is constructed _inside_ the view, so a rectangular background goes | |
361 // over the border in the rounded corners. To fix this, give the background a | |
362 // corner radius 1px smaller than the outer border, so it just reaches but | |
363 // doesn't cover it. | |
364 const int kOverlayCornerRadius = | |
365 GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius(); | |
366 overlay_view_->set_background(new AppListOverlayBackground( | |
367 kOverlayCornerRadius - (SupportsShadow() ? 0 : 1))); | |
368 | |
369 AddChildView(overlay_view_); | |
370 | |
371 if (delegate_) | 320 if (delegate_) |
372 delegate_->ViewInitialized(); | 321 delegate_->ViewInitialized(); |
373 } | 322 } |
374 | 323 |
375 void AppListView::OnBeforeBubbleWidgetInit( | 324 void AppListView::OnBeforeBubbleWidgetInit( |
376 views::Widget::InitParams* params, | 325 views::Widget::InitParams* params, |
377 views::Widget* widget) const { | 326 views::Widget* widget) const { |
378 #if defined(USE_AURA) && !defined(OS_CHROMEOS) | 327 #if defined(USE_AURA) && !defined(OS_CHROMEOS) |
379 if (delegate_ && delegate_->ForceNativeDesktop()) | 328 if (delegate_ && delegate_->ForceNativeDesktop()) |
380 params->native_widget = new views::DesktopNativeWidgetAura(widget); | 329 params->native_widget = new views::DesktopNativeWidgetAura(widget); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 speech_view_->layer()->SetTransform(speech_transform); | 482 speech_view_->layer()->SetTransform(speech_transform); |
534 } | 483 } |
535 | 484 |
536 if (will_appear) | 485 if (will_appear) |
537 speech_view_->SetVisible(true); | 486 speech_view_->SetVisible(true); |
538 else | 487 else |
539 app_list_main_view_->SetVisible(true); | 488 app_list_main_view_->SetVisible(true); |
540 } | 489 } |
541 | 490 |
542 } // namespace app_list | 491 } // namespace app_list |
OLD | NEW |